.NET Core不了解Windows 1252,如何解决?

编程入门 行业动态 更新时间:2024-10-25 16:27:41
本文介绍了.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,如何解决?

本文发布于:2023-11-16 18:41:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606827.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不了解   如何解决   Core   NET   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!