Open tanveerbadar opened 7 months ago
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.
Author: | tanveerbadar |
---|---|
Assignees: | - |
Labels: | `area-System.Text.Json`, `untriaged` |
Milestone: | - |
This isn't related to polymorphism per se, here's a minimal reproduction:
partial class BaseType
{
public string? MoreData { get; set; }
}
partial class DerivedType : BaseType
{
[JsonPropertyName("MoreData2")]
public new string? MoreData { get; set; }
}
[JsonSerializable(typeof(DerivedType))]
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
partial class MyContext : JsonSerializerContext;
TL;DR the fast-path serializer isn't correctly deduplicating shadowed members when the shadowing type uses a custom property name.
Description
System.Text.Json source generator is generating code which fails to compile if the following conditions are met:
[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
Reproduction Steps
Following code demonstrates the problem
Expected behavior
Generated code should have no compilation errors.
Actual behavior
Generated code has 2 locals with the same name.
Regression?
Not sure
Known Workarounds
No response
Configuration
Using .net 8, Windows 10, x64.
Other information
No response