Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This program works just fine when compiled for .NET 4 but does not when compiled for .NET Core. I understand the error about encoding not supported but not how to fix it.

Public Class Program
    Public Shared Function Main(ByVal args As String()) As Integer
        System.Text.Encoding.GetEncoding(1252)
    End Function
End Class
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

To do this, you need to register the CodePagesEncodingProvider instance from the System.Text.Encoding.CodePages package.

To do that, install the System.Text.Encoding.CodePages package:

dotnet add package System.Text.Encoding.CodePages

Then (after implicitly or explicitly running dotnet restore) you can call:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc1252 = Encoding.GetEncoding(1252);

Alternatively, if you only need that one code page, you can get it directly, without registration:

var enc1252 = CodePagesEncodingProvider.Instance.GetEncoding(1252);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...