Encoding issue with .NET Core 3.1

Post Reply
sku
Posts: 2
Joined: Fri Oct 02, 2020 11:49 am

Encoding issue with .NET Core 3.1

Post by sku » Fri Oct 02, 2020 12:00 pm

I created 2 console applications (.NET Core 3.1 and .NET Framework 4.6.1) running exactly the same code:

Code: Select all

        public static async Task SendHelloWorld()
        {
            LogManager.SetLoggerFactory(new ConsoleLogFactory(LogLevel.Verbose));

            using (SmppClient client = new SmppClient())
            {
                try
                {
                    if (await client.ConnectAsync(new DnsEndPoint("xxx", 4200, AddressFamily.InterNetwork)))
                    {
                        BindResp bindResp = await client.BindAsync("xxx", "xxx");

                        if (bindResp.Header.Status == CommandStatus.ESME_ROK)
                        {
                            var submitResp = await client.SubmitAsync(
                                SMS.ForSubmit()
                                    .From("xxx")
                                    .To("xxx")
                                    .Coding(DataCodings.Latin1)
                                    .Text("Bestätige deine Nummer mit folgendem Link um zu deiner persönlichen"));

                            if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK))
                            {
                                client.Logger.Info("Message has been sent.");
                            }
                        }

                        await client.DisconnectAsync();
                    }
                }
                catch (Exception ex)
                {
                    client.Logger.Error("Failed send message", ex);
                }
            }
        }
With .NET Framework 4.6.1 everything works as expected, but with .NET Core 3.1 all the German characters ("ä", "ö") are displayed incorrectly in the delivered message. A possible workaround is to manually convert to ISO-8859-1 as following:

Code: Select all

            Encoding iso = Encoding.GetEncoding("ISO-8859-1");
            byte[] isoBytes = iso.GetBytes("Bestätige deine Nummer mit folgendem Link um zu deiner persönlichen");
But this results in sending 2 SMS instead of just one.

Any help with this is really appreciated.
alt
Site Admin
Posts: 985
Joined: Tue Apr 25, 2006 9:45 am

Re: Encoding issue with .NET Core 3.1

Post by alt » Fri Oct 02, 2020 2:12 pm

Hi

You need to map Latin1 data coding to desired .NET Encoding. It seems .NET Core 3.1 and .NET 4.6.1 return different default encoding.

Code: Select all

client.EncodingMapper.MapEncoding(DataCodings.Latin1, Encoding.GetEncoding("ISO-8859-1"));
https://docs.inetlab.com/smpp/v2.8/arti ... oding.html
sku
Posts: 2
Joined: Fri Oct 02, 2020 11:49 am

Re: Encoding issue with .NET Core 3.1

Post by sku » Fri Oct 02, 2020 4:03 pm

Thank you for the fast reply. This solved the issue.
Post Reply