'Why is System.-Encoding and the Default-Encoding different (.NET Core)?

I have a C# .NET Core application.
I run

System.Console.WriteLine(System.Text.Encoding.Default.WebName);

and I get utf-8

However, if I open PowerShell, and issue

[System.Text.Encoding]::Default

I get

IsSingleByte      : True
BodyName          : iso-8859-1
EncodingName      : Westeuropäisch (Windows)
HeaderName        : Windows-1252
WebName           : Windows-1252
WindowsCodePage   : 1252
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 1252

Why is the system-encoding different from the default-encoding ?
And how do I get the system-encoding under these circumstances ?
I mean, I figured out I can get Windows-Codepage 1252 in .NET Core with

System.Text.Encoding.GetEncoding("iso-8859-1").WindowsCodePage

but how do I determine the system's codepage ?



Solution 1:[1]

You can simply use

System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
var enc = System.Text.Encoding.GetEncoding(0);

The value 0 means CP_ACP for the native API. This continues to work on .NET 6.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Filip Navara