Windows -1252 不支持编码名称 [英] Windows -1252 is not supported encoding name
问题描述
我正在使用 Windows 10 通用应用程序和 ARM CPU 为 Raspberry Pi 创建应用程序.我收到以下编码错误:
I am working with windows 10 universal App and the ARM CPU to create apps for the Raspberry Pi. I get the following error with encoding:
附加信息:windows-1252"不是受支持的编码名称.有关定义自定义编码的信息,请参阅 Encoding.RegisterProvider 方法的文档.
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=...");
MySqlCommand cmd;
conn.Open();
cmd = new MySqlCommand("Select * from ...");
var dr = cmd.ExecuteReader();
int count = 0;
while (dr.Read())
count += 1;
var dialog = new MessageDialog((count == 1) ? "Logged In" : "Error");
await dialog.ShowAsync();
}
catch (Exception ex)
{
var dialog = new MessageDialog(ex.Message);
await dialog.ShowAsync();
}
finally { conn.Close(); }
}
}
我在这行代码中得到错误
I get the error in this line of code
dr = cmd.ExecuteReader();
在我习惯之前
conn.open();
但是我能够通过添加来解决它
But I was able to solve it by adding
charset=utf8
到连接字符串.
我该如何解决这个错误?
How can I solve this error?
推荐答案
从 .NET Core 2.2 项目中,我必须通过 Nuget 安装以下两个包:
From a .NET Core 2.2 project, I had to install via Nuget the following two packages:
(System.Text.Encoding & System.Text.Encoding.CodePages)
(System.Text.Encoding & System.Text.Encoding.CodePages)
那你必须在使用库之前进行设置:
Then you have to set it before the use of libraries:
using System.Text;
…
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
...
}
这篇关于Windows -1252 不支持编码名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!