In .NET Core applications, when handling data with a character set that is not bundled with .NET Standard, you may come across the following error message: “Unable to translate bytes [..] at index x from specified code page to Unicode”.
To resolve this issue, you will need to install the System.Text.Encoding.CodePages dependency
-
Install-Package System.Text.Encoding.CodePages
, and add the following line of code to your application at the start of your code:
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
In the following example, I have used the CData ADO.NET Provider for Amazon Marketplace to create a connection to our Japanese Amazon Marketplace account in Entity Framework Core 6.0 (please consult the “Getting Started with EFCore” section of the driver’s documentation: https://cdn.cdata.com/help/ONJ/ado/pg_efCoreOverview.htm ).
The API’s charset is charset=Windows-31J:
![](https://uploads-us-west-2.insided.com/cdata-en/attachment/8cfef000-8998-49d6-a954-9775a9747bfa.png)
This character encoding isn’t supported by default in .NET Core, hence the error:
![](https://uploads-us-west-2.insided.com/cdata-en/attachment/830afb39-10b9-47c6-aa04-b76a016bdae7.png)
For more information about supported code page encodings in .NET Core, please refer to Microsoft’s documentation: https://learn.microsoft.com/en-us/dotnet/api/system.text.codepagesencodingprovider?view=net-8.0#remarks
In order to retrieve all the data, I added the dependency and registered the encoding:
![](https://uploads-us-west-2.insided.com/cdata-en/attachment/9dbb00d2-d77c-4c5b-91cd-aa98ae627b40.png)
Please reach out to support@cdata.com if you run into any issues.