.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”
2、🥈解决办法
在NuGet中下载“System.Text.Encoding.CodePages”包:
然后在var bytes = Encoding.GetEncoding("GB2312").GetBytes(strTemp);之前注册对编码进行注册:Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
到此,问题解决!