System.NotSupportedException: No data is available for encoding 1252

后端 未结 2 1631
渐次进展
渐次进展 2021-01-01 10:18

I\'m working with a Trust Commerce Tutorial on how to generate a payment token that will allow customers to use the TC Trustee Host payment form. I was given an example on h

相关标签:
2条回答
  • 2021-01-01 11:04

    What ckuri said. Just to be clear, you need the following line of code before opening the stream (steps 2,3):

    System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

    ExcelDataReader - Important note on .NET Core

    By default, ExcelDataReader throws a NotSupportedException "No data is available for encoding 1252." on .NET Core.

    To fix, add a dependency to the package System.Text.Encoding.CodePages and then add code to register the code page provider during application initialization (f.ex in Startup.cs):

    System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

    This is required to parse strings in binary BIFF2-5 Excel documents encoded with DOS-era code pages. These encodings are registered by default in the full .NET Framework, but not on .NET Core.

    0 讨论(0)
  • 2021-01-01 11:05

    .NET Core supports only ASCII, ISO-8859-1 and Unicode encodings, whereas .NET Framework supports much more.

    However, .NET Core can be extended to support additional encodings like Windows-1252, Shift-JIS, GB2312 by registering the CodePagesEncodingProvider from the System.Text.Encoding.CodePages NuGet package.

    After the NuGet package is installed the following steps as described in the documentation for the CodePagesEncodingProvider class must be done to register the provider:

    1. Add a reference to the System.Text.Encoding.CodePages.dll assembly to your project.
    2. Retrieve a CodePagesEncodingProvider object from the static Instance property.
    3. Pass the CodePagesEncodingProvider object to the Encoding.RegisterProvider method.
    0 讨论(0)
提交回复
热议问题