“No mapping for the Unicode character exists in the target multi-byte code page”

  

Usually when I see this error [Wayback] “No mapping for the Unicode character exists in the target multi-byte code page” – Google Search, it is in legacy code that uses string buffers where decoding or decompressing data into.
This is almost always wrong no matter what kind of data you use, as it will depend in your string encoding.
I have seen it happen especially in these cases:

base64 decoding from string to string (solution: decode from a string stream into a binary stream, then post-process from there)
zip or zlib decompress from binary stream to string stream, then reading the string stream (solution: decompress from binary stream to binary stream, then post-process from there)

Most cases I encountered were in Delphi and C code, but surprisingly I also bumped into C# exhibiting this behaviour.
I’m not alone, just see these examples from the above Google search:

[WayBack] C# metro No mapping for the Unicode character exists in the target multi-byte code page – Stack Overflow
[WayBack] No mapping for the Unicode character exists in the target multi-byte code page – The file must be in UTF-8 or UTF-16 encoding. :: WinSCP
[WayBack] file io – WinRT No mapping for the Unicode character exists in the target multi-byte code page – Stack Overflow
[WayBack] No mapping for the Unicode character exists in the target multi-byte code page · Issue #110 · VBA-tools/VBA-Web · GitHub
Fixed issues:

[WayBack] Error while import file · Issue #566 · HeidiSQL/HeidiSQL · GitHub
[WayBack] EEncodingError: No mapping for the Unicode character in target multi-byte code page · Issue #515 · HeidiSQL/HeidiSQL · GitHub

[WayBack] No mapping for the Unicode character exists in the target multi-byte code page ? (Delphi XE6) – Stack Overflow (tries to decompress a string)
[WayBack] android – delphi xe6 No mapping for the Unicode character exists in the target multi-byte code page – Stack Overflow (tries to always download HTTP with the same encoding, despite it can have any encoding)
[WayBack] delphi – What could cause “No mapping for the Unicode character exists in the target multi-byte code page”? – Stack Overflow (which was a bug in the Delphi RTL method TFile.AppendAllBytes which is still present in Delphi 10.2 Tokyo, and likely newer versions)
Two artifacts of the same resolved bug in the DevExpress ExpressRichEdit Control (they do fix their bugs and release fixed versions soon):

[WayBack] T663543 – Saving document as UTF-8 plain text doesn’t write the preamble | DevExpress Support Center
[WayBack] T664497 – The “No mapping for the Unicode character exists in the target multi-byte code page” error occurs on loading a TXT file that doesn’t have an encoding preamble | DevExpress Support Center

–jeroen

Comments are closed.