Encoding.RegisterProvider(EncodingProvider) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers an encoding provider.
public:
static void RegisterProvider(System::Text::EncodingProvider ^ provider);
[System.Security.SecurityCritical]
public static void RegisterProvider(System.Text.EncodingProvider provider);
public static void RegisterProvider(System.Text.EncodingProvider provider);
[<System.Security.SecurityCritical>]
static member RegisterProvider : System.Text.EncodingProvider -> unit
static member RegisterProvider : System.Text.EncodingProvider -> unit
Public Shared Sub RegisterProvider (provider As EncodingProvider)
Parameters
- provider
- EncodingProvider
A subclass of EncodingProvider that provides access to additional character encodings.
- Attributes
Exceptions
provider is null.
Remarks
The RegisterProvider method allows you to register a class derived from EncodingProvider that makes character encodings available on a platform that does not otherwise support them. Once the encoding provider is registered, the encodings that it supports can be retrieved by calling any Encoding.GetEncoding overload. If there are multiple encoding providers, the Encoding.GetEncoding method attempts to retrieve a specified encoding from each provider starting with the one most recently registered.
Registering an encoding provider by using the RegisterProvider method also affects the behavior of GetEncoding(Int32) when passed an argument of 0. This is particularly important in .NET Core and later versions where the default behavior for GetEncoding(Int32) with codepage 0 is to return UTF-8:
If the registered provider is CodePagesEncodingProvider:
- On Windows, GetEncoding(Int32) with
codepage0 returns the encoding that matches the system's active code page (same as .NET Framework behavior). - On non-Windows platforms, it still returns UTF-8.
- On Windows, GetEncoding(Int32) with
If a custom encoding provider is registered: The provider can choose which encoding to return when GetEncoding(Int32) is passed an argument of
0. The provider can also choose to not handle this case by returningnullfrom its EncodingProvider.GetEncoding method, in which case the default UTF-8 behavior is used.
If multiple providers are registered, GetEncoding(Int32) attempts to retrieve the encoding from the most recently registered provider first.
Starting with .NET Framework 4.6, .NET Framework includes one encoding provider, CodePagesEncodingProvider, that makes the encodings available that are present in the full .NET Framework but are not available in the Universal Windows Platform. By default, the Universal Windows Platform only supports the Unicode encodings, ASCII, and code page 28591.
If the same encoding provider is used in multiple calls to the RegisterProvider method, only the first method call registers the provider. Subsequent calls are ignored.
If the RegisterProvider method is called to register multiple providers that handle the same encoding, the last registered provider is the used for all encoding and decoding operations. Any previously registered providers are ignored.