.Net Core报“‘GB2312‘ is not a supported encoding name. For information on defining a custom encod”的错误

1、🥇问题描述

在.Net Core中使用Encoding.GetEncoding("GB2312")报如下错误:

System.ArgumentException:“'GB2312' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. Arg_ParamName_Name”

image


2、🥈解决办法

在NuGet中下载“System.Text.Encoding.CodePages”包:

image

然后在var bytes = Encoding.GetEncoding("GB2312").GetBytes(strTemp);之前注册对编码进行注册:Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

image

到此,问题解决!

posted @ 2024-01-29 13:20  Qubernet  阅读(69)  评论(0编辑  收藏  举报
🛧