Encoding problem

Hello, I’ve upgraded SDK from .NetFramework version to newest .NET CORE version (10.*).
After creating new Intf class/service iI’m issuing response encoding problems with polish characters. ‘ł’ letter is being ? char. I’ve tried to set DefaultStringEncoding to Win1250 on BinMessage, also set SerializerInstance to ‘new BinSerializer(Encoding.GetEncoding(1250))’ but problem appears as well. What can I do to solve this issue?

Are you using WideString or String type in your RODL (if your server is RODL based)?

8-bit Strings are inherently unsafe these days, unless you can be 100% sure both sides use there same default code page and/or you’re only transferring plain ASCII data (the latter you clearly are not ;), so I winkled recommend using Utf8String or 16-bit WideString (UTF-16), for all String parameters, if you can.

I’m using AnsiString as parameters

That’s your problem, then, yeah. Are you in a position where you can change to WideString (without wore compatibility with existing clients in the wild to worry about? If so, I suggest to do that.

If not, Changing to Utf8Stirng should be safe-ish, as it will remain wire-compatible with AniString, and the breakage you get for old clients wont be “worse” than the issues you have now with code page mismatches.

Setting SerializerInstance directly won’t have any effect (actually this property should not be used at all and will be removed in the next releases).

Setting DefaultStringEncoding is the way you need to use. However you need to use correct encoding to be able to read non-ANSI chars sent as 8-bit string. You need to set here encoding that is used by the client host.

The code that reads the string is similar to this:

		public String StringFromBuffer(Byte[] buffer, Encoding encoding)
			return encoding.GetString(buffer, 0, buffer.Length);

Additionally, .NET Core / .NET 5.0 / .NET 6.0 platforms doesn’t provide built-in support for non-default Encodings (including 1250) at all.

One have to reference the package System.Text.Encoding.CodePages and to register code page providers at app startup using code like

 var message =  new BinMessage
                DefaultStringEncoding = Encoding.GetEncoding(1250),
                EnforceMaxMessageSize = false

I’ve set DefaultStringEncoding to Win-1250 as shown, but problem with polish chars still occurs

This means that your client app uses code page different from 1250 to send the data.

What is the shar in question? How is it represented on the client side? Mean, which exactly char code is used to represent this char client-side?