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
, and add the following line of code to your application at the start of your code:
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:
This character encoding isn’t supported by default in .NET Core, hence the error:
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:
Please reach out to firstname.lastname@example.org if you run into any issues.