My .NET application servers is providing services in .NET Framework(4.5.2) on Windows and Mono(5.2.0.224) on CentOS(6,7).
And Client made in Delphi(2007) communicates with server using BinMessage.
In the test, client with with .NET Framework on Windows server was good but not Mono on CentOS.
And the cause was AnsiString datatype in BinMessage.
(Default Encoding in .Net Framework on Windows would be different depends on country and region but it would not be UTF-8.)
and Mono on CentOS is
System.Text.UTF8Encoding (utf-8 / 65001).
So the results of BinHelpers.AnsiStringToBuffer is different depends on platform.
Can I get an API to change the AnsiString encoding type of BinMessage?
or Is it Possible to change Mono’s default encoding?
What would be a good idea to solve this problem?
Short answer: don’t use AnsiString of you need to preserve chars > 127 between systems where you don’t control the code page on both sides. That’s what Wide and UTF8 strings are for. Ansi strings are “by design” imprecise.
Seems this happens on OSes that don’t have such thing as a codepage. I’ll log an issue to use ASCII encoding if the default one used by the system is UTF8. This means that non-ANSI chars will be replaced with ‘?’ chars, but atm they aren’t transferred correctly anyway.
Note: You still won’t be able to transfer non-ANSI chars via AnsiString datatype from Windows to Mono using the AnsiString datatype. You have to use proper datatype for this