-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.Text.Json is adding EqualityContract properties metadata for records #77675
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionPossible regression from #58136, cc. @eiriktsarpalis.
Reproduction StepsPaste the following code: public sealed record Test;
[JsonSerializable(typeof(Test))]
public sealed partial class DAJsonSerializerContext : JsonSerializerContext
{
}
### Expected behavior
The generated code for `Test` should not include the "EqualityContract" property.
### Actual behavior
```csharp
// <auto-generated/>
#nullable enable annotations
#nullable disable warnings
// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0618
namespace MyTestProject
{
public sealed partial class DAJsonSerializerContext
{
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::MyTestProject.Test>? _Test;
/// <summary>
/// Defines the source generated JSON serialization contract metadata for a given type.
/// </summary>
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::MyTestProject.Test> Test
{
get => _Test ??= Create_Test(Options);
}
// Intentionally not a static method because we create a delegate to it. Invoking delegates to instance
// methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk.
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::MyTestProject.Test> Create_Test(global::System.Text.Json.JsonSerializerOptions options)
{
global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::MyTestProject.Test>? jsonTypeInfo = null;
global::System.Text.Json.Serialization.JsonConverter? customConverter;
if (options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(options, typeof(global::MyTestProject.Test))) != null)
{
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::MyTestProject.Test>(options, customConverter);
}
else
{
global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::MyTestProject.Test> objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::MyTestProject.Test>()
{
ObjectCreator = static () => new global::MyTestProject.Test(),
ObjectWithParameterizedConstructorCreator = null,
PropertyMetadataInitializer = _ => TestPropInit(options),
ConstructorParameterMetadataInitializer = null,
NumberHandling = default,
SerializeHandler = TestSerializeHandler
};
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::MyTestProject.Test>(options, objectInfo);
}
return jsonTypeInfo;
}
private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] TestPropInit(global::System.Text.Json.JsonSerializerOptions options)
{
global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[1];
global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Type> info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<global::System.Type>()
{
IsProperty = true,
IsPublic = false,
IsVirtual = false,
DeclaringType = typeof(global::MyTestProject.Test),
Converter = null,
Getter = null,
Setter = null,
IgnoreCondition = null,
HasJsonInclude = false,
IsExtensionData = false,
NumberHandling = default,
PropertyName = "EqualityContract",
JsonPropertyName = null
};
global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo propertyInfo0 = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Type>(options, info0);
properties[0] = propertyInfo0;
return properties;
}
private void TestSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::MyTestProject.Test? value)
{
if (value == null)
{
writer.WriteNullValue();
return;
}
writer.WriteStartObject();
writer.WriteEndObject();
}
}
} Regression?Seems like it might be the case, yes. I'm using Known WorkaroundsNone. Configuration.NET Standard 2.0 class library, using System.Text.Json Other informationNo response
|
I was able to repro. Just to explicitly state the distinction here vs #58136: We do have a change where the "EqualityContract" property is included in the list of cc @krwq @eiriktsarpalis do you know why this property is being added (say a side effect of contract generation changes in 7.0)? |
I checked and it seems this property is also being added in .NET 6, so based on the feedback in #58136 there might have been a change/regression in .NET 6 GA. Further investigation is needed to determine if and why such a change was made. |
Related to #66679, as they both seem to stem from us not honoring |
@eiriktsarpalis Just for additional context, this is also one of the group of issues we're hitting in the Microsoft Store, should we add |
Description
Possible regression from #58136, cc. @eiriktsarpalis.
Reproduction Steps
Paste the following code:
Expected behavior
The generated code for
Test
should not include the "EqualityContract" property.Actual behavior
Regression?
Seems like it might be the case, yes. I'm using
7.0.0-rc.2.22472.3
.Known Workarounds
None.
Configuration
.NET Standard 2.0 class library, using System.Text.Json
7.0.0-rc.2.22472.3
.The text was updated successfully, but these errors were encountered: