背景
在使用.net 5构建应用时,在处理某些编码问题使用了GB2312,应用运行后报错。经过确认知道了编码 GB2312 默认不支持。
异常信息
Not Support Encoding’GB2312′ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. (Parameter ‘name’)
System.Exception: Not Support Encoding’GB2312′ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. (Parameter ‘name’)
解决办法
添加引用包

System.Text.Encoding.CodePages
注册
在使用System.Text.Encoding.GetEncoding ("GB2312")之前,在代码中执行注册
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
转载请注明:清风亦平凡 » .NET 5中使用GB2312编码报错的问题
支付宝扫码打赏
微信打赏