在要求输入邮箱的文本域,请填写真实的邮件地址。非真实邮件地址,将收不到回复信息。

.NET 5中使用GB2312编码报错的问题

.net core 清风 630℃ 0评论

背景

在使用.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’)

解决办法

添加引用包

.NET 5中使用GB2312编码报错的问题-第0张图片
System.Text.Encoding.CodePages

注册

在使用System.Text.Encoding.GetEncoding ("GB2312")之前,在代码中执行注册

 System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);



转载请注明:清风亦平凡 » .NET 5中使用GB2312编码报错的问题

喜欢 (3)or分享 (0)
支付宝扫码打赏 支付宝扫码打赏 微信打赏 微信打赏
头像
发表我的评论
取消评论

CAPTCHA Image
Reload Image
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址