.NET Core doesn't know about Windows 1252, how to fix?

故事扮演 提交于 2019-11-26 14:31:33

To do this, you need to register the CodePagesEncodingProvider instance from the System.Text.Encoding.CodePages package.

To do that, install the System.Text.Encoding.CodePages package:

dotnet add package System.Text.Encoding.CodePages

Then (after implicitly or explicitly running dotnet restore) you can call:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc1252 = Encoding.GetEncoding(1252);

Alternatively, if you only need that one code page, you can get it directly, without registration:

var enc1252 = CodePagesEncodingProvider.Instance.GetEncoding(1252);

Please write:

<ItemGroup>
    <PackageReference Include="System.Text.Encoding.CodePages" Version="4.3.0" />
</ItemGroup>

in csproj.

In package console write ' dotnet restore', restore assemblies.

and wite this code for sample:

public class MyClass
{
    static MyClass()
    {
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!