.NET Core 2.0 Encoding.GetEncoding

Hello everyone. I ran into a problem: I need to send a message to the mailbox in the encoding koi8-u(21866). Using the package System.Text.Encoding.CodePages:

        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        MailAddress fr = new MailAddress("***@**.com", "Name");
        MailAddress to = new MailAddress("***@**.com");
        MailMessage m = new MailMessage(fr, to)
        {
            Body = "test",
            BodyEncoding = Encoding.GetEncoding("koi8-u")
        };
        await smtp.SendMailAsync(m);

But when sending it, I get: No data is available for encoding 21866. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

In the usual way .NET Framework-e everything is perfectly sent, in .NET Core, alas. How can this be resolved?

P. S: such the situation is the same for windows-1252 and others.

Author: Ares, 2017-12-08

1 answers

Just plug in NuGet - a package with advanced encodings:

System.Text.Encoding.CodePages

And before using them, register them:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);   

It should help.

 6
Author: Anatol, 2017-12-11 05:46:39