Encoding issue with .NET Core 3.1
Posted: 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:
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:
But this results in sending 2 SMS instead of just one.
Any help with this is really appreciated.
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);
}
}
}
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");
Any help with this is really appreciated.