Windows -1252不支持编码名称. C#

前端之家收集整理的这篇文章主要介绍了Windows -1252不支持编码名称. C#前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Windows 10 Universal App和ARM cpu为Raspberry Pi创建应用程序.编码时出现以下错误

Additional information: ‘windows-1252’ is not a supported encoding name. For information on defining a custom encoding,see the documentation for the Encoding.RegisterProvider method.

这是我的代码.

private async void Login(string passcode)
    {
        try
        {
            MysqLConnection conn = new MysqLConnection("Server=127.0.0.1;Port=3306;Database=database;Uid=username;Pwd=password;SslMode=None;charset=utf8");
            MysqLCommand cmd;

            conn.Open();

            cmd = new MysqLCommand("Select * from users where User = '" + passcode + "'",conn);

            MysqLDataReader dr;

            dr = cmd.ExecuteReader();

            int count = 0;

            while (dr.Read())
            {
                count += 1;
            }

            if(count == 1)
            {
                var dialog = new MessageDialog("Logged In");
                await dialog.ShowAsync();
            }
            else
            {
                var dialog = new MessageDialog("Error");
                await dialog.ShowAsync();
            }

        }
        catch (Exception ex)
        {
            if (ex is MysqLException)
            {
                MysqLException exl = (MysqLException)ex;
                var dialog = new MessageDialog(ex.Message + Environment.NewLine + exl.Number);
                await dialog.ShowAsync();
            }
            else
            {
                var dialog = new MessageDialog(ex.Message + Environment.NewLine);
                await dialog.ShowAsync();
            }

            //throw;
        }
        finally
        {
            conn.Close();
        }


    }
}

我在这行代码中得到了错误

dr = cmd.ExecuteReader();

在我习惯之前

conn.open();

但我能够通过添加解决

charset=utf8

到连接字符串.

我该如何解决这个错误

解决了这个问题
System.Text.EncodingProvider ppp;
ppp = System.Text.CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(ppp);

猜你在找的Windows相关文章