[Breaking change]: BinaryReader.GetString() will return "\uFFFD" on malformed encoded string sequences. #42564
Closed
1 of 3 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
in-pr
This issue will be closed (fixed) by an active pull request.
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Description
dotnet/runtime#80331 introduced a minor breaking change only affecting malformed encoded payloads.
Prior to .NET 9, a malformed encoded string [0x01, 0xC2] parsed with BinaryReader.ReadString() would return an empty string.
ON .NET 9, it would return "\uFFFD" which is the REPLACEMENT CHARACTER used to replace an unknown, unrecognised, or unrepresentable character. We accepted this change because it only affected malformed payloads and matches Unicode standards.
Version
.NET 9 Preview 7
Previous behavior
New behavior
Type of breaking change
Reason for change
Perf improvement affecting a rare scenario.
Recommended action
If you want to keep the previous behavior where incomplete byte sequence were being omitted at the end of the string, you can TrimEnd("\uFFFD") the result.
Feature area
Core .NET libraries
Affected APIs
BinaryReader.ReadString()
Associated WorkItem - 320280
The text was updated successfully, but these errors were encountered: