A package replacement for .Net Core 3.0+ UTF8 string encoding/decoding and windows-1252 codepage implementation to match .Net Framework behavior.
As of .Net Core 3.0+ a bug was fixed in Microsoft's UTF8 implementation that changes the behavior of UTF8 string encoding and decoding. This package offers the legacy behavior that is still present in .Net Framework today for maximum compatibility when using .Net Core 3.0+. Also included is Windows-1252 codepage support which was made an optional package for .Net Core and no longer included.
Install Text.UTF8.Legacy from the Package Manager Console:
PM> Install-Package Text.UTF8.Legacy
UTF8 String decoding
using Text.UTF8.Legacy;
var bytes = // byte representation of a UTF8 string
var utf8String = Text.UTF8.Legacy.Encoding.UTF8.GetString(bytes);
UTF8 String encoding
using Text.UTF8.Legacy;
var string = "A test string";
var bytes = Text.UTF8.Legacy.Encoding.UTF8.GetBytes(string);
Encoding using Windows-1252 codepage encoding:
var string = "A test string";
var codepage1252Encoder = CodePagesEncodingProvider.Instance.GetEncoding(1252);
var bytes = codepage1252Encoder.GetBytes(string);
See .NET Core 3.0 follows Unicode best practices when replacing ill-formed UTF-8 byte sequences Issue Report