标签:The ogr nta [] instance 没有 www. net red
问题描述:新建.Net Core项目,出现System.NotSupportedException:“No data is available for encoding 1252(或Shift-JIS、GB2312). For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.”
检测:
1 EncodingInfo [] encodings= Encoding.GetEncodings(); 2 foreach (var i in encodings) 3 { 4 Console.WriteLine(i.CodePage+" "+i.DisplayName); 5 }
该项目显示结果:
解决办法:
异常信息中提到了Encodeing.RegisterProvider,.NET Core 在默认情况下是没有注册EncodeProvider,需要我们们手动自己去注册。
在NuGet包添加System.Text.Encoding.CodePages
1 using System; 2 using System.Text; 3 4 namespace FastDBF_Core_test 5 { 6 class Program 7 { 8 static void Main(string[] args) 9 { 10 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 11 Encoding encoding1 = Encoding.GetEncoding(1252); 12 Console.WriteLine(encoding1.WebName); 13 Encoding encoding2 = Encoding.GetEncoding("GB2312"); 14 Console.WriteLine(encoding2.WebName); 15 Console.ReadKey(); 16 } 17 } 18 }
输出:
参考:https://www.cnblogs.com/Redefine/p/6877580.html
标签:The ogr nta [] instance 没有 www. net red
原文地址:https://www.cnblogs.com/liuz646-blog/p/9993844.html