本文介绍了.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,如何解决?
发布评论