How to determine the default encoding in a portable class library?

With .NET 4.6 I can determine the current code page with

 System.Text.Encoding.Default 

Now I'm trying to migrate a class library that reads files from the standard class library to a portable class library, supporting ASP.NET Core 5. Encoding.Default not available in this configuration.

Of course, any last file must be saved in UTF-8 encoding, but I cannot guarantee that all files are stored in this encoding.

Is there any other way to get the default codepage?

I looked at the source source and found that Encoding.Default implemented (more ore less) with a call to Win32 Api ...

+5
source share
1 answer

According to the documentation here: Encoding.GetEncoding Method (Int32) , you can use Encoding.GetEncoding (0) to get the default encoding,

+7
source

Source: https://habr.com/ru/post/1244858/


All Articles