-
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 source generator ignores properties from base records defined in separate assemblies #61772
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsDescriptionProperties of a base record defined in a referenced NuGet package are ignored when creating a JsonSerializerContext. Reproduction StepsCreate a project with a record: public record FooData
{
public virtual int FooValue { get; set; }
} Create a NuGet package. Create a second project and reference the NuGet package: public record BarData : Foo.FooData
{
public int BarValue { get; set; }
} Create a [JsonSerializable(typeof(BarData))]
public partial class BarJsonSerializerContext : JsonSerializerContext { } Expected behaviorThe generated context ( Actual behaviorThe generated context ( Regression?No response Known WorkaroundsReference the project with the base types directly if possible instead of using a NuGet package. Configuration.net 6.0.100 Other informationNo response
|
I can reproduce, the issue specifically impacts records inherited across projects. It doesn't seem to impact regular classes. I can reproduce using p2p references, so this is not exclusive to NuGet dependencies. Minimal reproduction: Class Librarypublic record LibRecord
{
public int LibValue { get; set; }
} Console Appusing System;
using System.Text.Json;
using System.Text.Json.Serialization;
var value = new AppRecord { LibValue = 1, AppValue = 2 };
string json = JsonSerializer.Serialize(value, MyJsonSerializerContext.Default.AppRecord);
Console.WriteLine(json);
public record AppRecord : LibRecord
{
public int AppValue { get; set; }
}
[JsonSerializable(typeof(AppRecord))]
public partial class MyJsonSerializerContext : JsonSerializerContext { } @layomia @ericstj seems like something to consider for servicing? |
Dupe - same underlying issue as #62374. |
Description
Properties of a base record defined in a referenced NuGet package are ignored when creating a JsonSerializerContext.
When working with classes it is working as expected.
Reproduction Steps
Create a project with a record:
Create a NuGet package.
Create a second project and reference the NuGet package:
Create a
JsonSerializerContext
:Expected behavior
The generated context (
BarJsonSerializerContext
) should handleFooValue
andBarValue
.Actual behavior
The generated context (
BarJsonSerializerContext
) handles onlyBarValue
.Regression?
No response
Known Workarounds
Reference the project with the base types directly if possible instead of using a NuGet package.
Configuration
.net 6.0.100
Other information
No response
The text was updated successfully, but these errors were encountered: