.NET Core不了解Windows 1252,如何解决? [英] .NET Core doesn't know about Windows 1252, how to fix?

查看:106
本文介绍了.NET Core不了解Windows 1252,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该程序在为.NET 4编译时可以正常运行,但为.NET Core编译时​​可以正常运行。我了解不支持编码的错误,但不知道如何解决。

This program works just fine when compiled for .NET 4 but does when compiled for .NET Core. I understand the error about encoding not supported but not how to fix it.

Public Class Program
    Public Shared Function Main(ByVal args As String()) As Integer
        System.Text.Encoding.GetEncoding(1252)
    End Function
End Class


推荐答案

为此,您需要注册 CodePagesEncodingProvider 实例,该实例来自 System.Text.Encoding.CodePages 包。

为此,请安装 System.Text.Encoding.CodePages程序包

dotnet add package System.Text.Encoding.CodePages

然后(隐式或显式运行 dotnet之后恢复),您可以致电:

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);

这篇关于.NET Core不了解Windows 1252,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆