我想在我的.netcore 2.0应用程序中使用windows-1252编码。根据文档,我需要添加this包并注册它以便能够使用此编码。但是它不起作用,当我调试它时,我看到提供者有0个编码
EncodingProvider provider = CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(provider);
根据我的理解,您的屏幕截图是指已经访问过的编码的缓存。因此,默认情况下,缓存为空。
要自己查看,请使用以下代码段:
// add a spy in visual studio with this :
// ((System.Text.CodePagesEncodingProvider)CodePagesEncodingProvider.Instance)._encodings
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// here the spy should have as value of "Count = 0"
var xx = Encoding.GetEncoding("Windows-1252");
// now the value is "Count = 1"
此编码实例不支持所有标准属性。他们中的一些人会抛出NotSupportedException
。