Encoding.GetEncoding可以UWP应用程序无法正常工作 [英] Encoding.GetEncoding can't work in UWP app

查看:252
本文介绍了Encoding.GetEncoding可以UWP应用程序无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编码一些文本文件的本地字符。



在我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆