Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
834 views
in Technique[技术] by (71.8m points)

c# - Encoding.GetEncoding can't work in UWP app

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...