Encoding.GetEncoding可以UWP应用程序无法正常工作 [英] Encoding.GetEncoding can't work in UWP app
问题描述
我需要编码一些文本文件的本地字符。
在我的Windows 8.1商店应用,我可以用 Encoding.GetEncoding()
方法通常为:
Encoding.GetEncoding(窗口-1254),
但在UWP应用程序,我得到这个异常:
更多信息:Windows的1254'是不支持的编码名称。有关定义自定义编码的信息,请参阅Encoding.RegisterProvider方法的文档。
块引用>
我不知道如何使它通过使用
Encoding.RegisterProvider
方式,任何想法?
解决方案<工作/ DIV>我们需要使用CodePagesEncodingProvider注册包括在特定的供应商扩展编码。请参见 CodePagesEncodingProvider 类
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding.GetEncoding(窗口-1254);
参考的https://msdn.microsoft.com/en-us/library/system.text.encodingprovider(v=vs.110).aspx
.NET框架类库提供了一个静态的财产,
的病人:System.Text.CodePagesEncodingProvider.Instance ,返回一个
EncodingProvider对象这使得整套编码的桌面.NET Framework类库上可用
提供给.NET核心
的应用程序。
块引用>
相关线程在MSDN论坛:的 Encoding.RegisterProvider - 如何使用
I need to encode some text files for native characters.
In my Windows 8.1 Store app, I could use
Encoding.GetEncoding()
method normally:Encoding.GetEncoding("windows-1254")
But in UWP app, I got this exception:
Additional information: 'windows-1254' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
I don't know how to make it work by using
Encoding.RegisterProvider
method, any ideas?解决方案We need to use the CodePagesEncodingProvider to register extended encodings included in that specific provider. See CodePagesEncodingProvider Class
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding.GetEncoding("windows-1254");
Ref https://msdn.microsoft.com/en-us/library/system.text.encodingprovider(v=vs.110).aspx
The .NET Framework Class Library provides one static property, P:System.Text.CodePagesEncodingProvider.Instance, that returns an EncodingProvider object that makes the full set of encodings available on the desktop .NET Framework Class Library available to .NET Core applications.
The related thread in MSDN forum: Encoding.RegisterProvider -- How to use?
这篇关于Encoding.GetEncoding可以UWP应用程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文