-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression in .NET 9-RC2: Case-insensitive handling of JsonNode #108790
Comments
Thanks for your detailed report. I've been able to trace back the issue to the new System.Collections.Generic.OrderedDictionary type on which var od = new OrderedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
od["case"] = "example1";
od["CASE"] = "example2";
foreach (var entry in od)
{
Console.WriteLine(entry); // [case, example2]
} |
Tagging subscribers to this area: @dotnet/area-system-collections |
Just to be clear, though, this is the expected behavior for OrderedDictionary, and matches what Dictionary does. The comparer is OrdinalIgnoreCase, and so the second write simply update's the existing key's value; it doesn't overwrite the key itself. |
On closer inspection, I don't believe this is a bug. This is common behaviour when overwriting entries in dictionaries with case insensitive comparison. Here's dictionary for example: var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
dict["case"] = "example1";
dict["CASE"] = "example2";
foreach (var entry in dict)
{
Console.WriteLine(entry); // [case, example2]
} The pre .NET 9 for |
Sure, it's easy to work around. But it's still a breaking change in If this won't be fixed, with the expectation that any affected users update their code, this behavior change should be mentioned in the list of breaking changes. |
Added
Tagging @dotnet/compat for awareness of the breaking change. |
Description
While analyzing why a unit test in .NET Aspire fails on .NET 9, I traced it down to a breaking change in System.Text.Json. I suspect the change was introduced in #103645. The regression is that when updating an existing key in a case-insensitive
JsonNode
with a different key casing, the original casing is preserved. This differs from the behavior in .NET 8, which adapts the existing key casing to the latest.This Aspire schema generation unit test breaks, after changing the target framework from .NET 8 to .NET 9. Even in the
release/9.0-rc1
branch of Aspire, the schema generator unit tests still run on .NET 8, which is probably why this wasn't noticed earlier.Below is the code for the failing Aspire test (both the test and the implementation haven't changed since Aspire v8):
Which fails with the following output on .NET 9:
Reproduction Steps
Program.cs
with the following code:System.Text.Json
, version 9.0.0-rc.2.24473.5.Expected behavior
When adding an entry to a case-insensitive
JsonNode
instance, which already contains the same key (but in different casing), then the casing of the new key is used.Actual behavior
When adding an entry to a case-insensitive
JsonNode
instance, which already contains the same key (but in different casing), then the casing of the original key is preserved.Regression?
Yes, the existing behavior of .NET 8 has changed in .NET 9.
Known Workarounds
No response
Configuration
Other information
/cc @eiriktsarpalis @eerhardt
The text was updated successfully, but these errors were encountered: