Skip to content

System.NotSupportedException: No data is available for encoding 1252 in .NET Core #113059

Closed
@rishabhIITB

Description

@rishabhIITB

Description

I am encountering an issue when trying to use Windows-1252 encoding in a .NET Core project. Despite registering CodePagesEncodingProvider, some encoding properties such as IsBrowserDisplay throw a System.NotSupportedException.

Reproduction Steps

Create a new .NET Core project
Install the Nuget package(dotnet add package System.Text.Encoding.CodePages)
Modify the csproj file to include the package

Update the Program.cs file as follows:

using System;
using System.Text;
class Program
{
static void Main()
{
// Register the code pages encoding provider
// Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding.RegisterProvider(provider: CodePagesEncodingProvider.Instance);
Encoding encoding1252 = Encoding.GetEncoding(1252);
if (encoding1252 != null)
{
Console.WriteLine("Encoding 1252 is present.");
// Print encoding details
Console.WriteLine($"Encoding Name: {encoding1252.EncodingName}");
Console.WriteLine($"Web Name: {encoding1252.WebName}");
Console.WriteLine($"Body Name: {encoding1252.BodyName}");
Console.WriteLine($"Header Name: {encoding1252.HeaderName}");
Console.WriteLine($"Code Page: {encoding1252.CodePage}");
Console.WriteLine($"Is Single Byte: {encoding1252.IsSingleByte}");
Console.WriteLine($"Is Browser Display: {encoding1252.IsBrowserDisplay}");
Console.WriteLine($"Is Browser Save: {encoding1252.IsBrowserSave}");
Console.WriteLine($"Is Mail News Display: {encoding1252.IsMailNewsDisplay}");
Console.WriteLine($"Is Mail News Save: {encoding1252.IsMailNewsSave}");
}
else
{
Console.WriteLine("Encoding 1252 is not present.");
}
}

Expected behavior

The encoding is retrieved successfully.
However, when accessing IsBrowserDisplay, a NotSupportedException is thrown.

Actual behavior

Despite registering CodePagesEncodingProvider, some encoding properties such as IsBrowserDisplay throw a System.NotSupportedException.

Regression?

No response

Known Workarounds

No response

Configuration

Version: 9.0.103

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.Encodingin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions