18

I am using Xamarin to develop an Android app, while trying to convert text to byte[] I get the following error:

no data is available for encoding 1252

My code:

byte[] mybyteA= Portable.Text.Encoding.UTF8.GetBytes(mystring);

Mono.Security.Cryptography.SHA224Managed sha22 = new _Mono.Security.Cryptography.SHA224Managed();
byte[] hash = sha22.ComputeHash(mybyteA);
5
  • Is this your actual code? The only part that deals with encodings is the first line, and it uses UTF-8, not cp1252... which line throws the exception exactly? Jun 12, 2016 at 22:00
  • Which line is causing the error? Are you sure you're supposed to use anything in the _Mono namespace?
    – Kroltan
    Jun 12, 2016 at 22:01
  • I should add this works in debugging but fails in release on the first line (actual encoding line)
    – Dwight
    Jun 12, 2016 at 22:04
  • I get the same error even if i use the system.security. the error is on the first line.
    – Dwight
    Jun 12, 2016 at 22:31

2 Answers 2

26

The Western Code page (1252) isn't being bundled into your final IPA/APK.

For iOS projects, include it by checking west under Project Properties -> iOS Build -> Internationalization:

enter image description here

For Android projects, include it by checking west under Project Properties -> Android Build -> Linker -> Internationalization:

enter image description here

12

In Visual Studio, you must go to the properties window of each project:

iOS

You must scroll down until 'west'

enter image description here

Android enter image description here

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.