Skip to content

System.Text.Json source generator ignores properties from base records defined in separate assemblies #61772

@Memoryfox

Description

@Memoryfox

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:

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 JsonSerializerContext:

[JsonSerializable(typeof(BarData))]
public partial class BarJsonSerializerContext : JsonSerializerContext { }

Expected behavior

The generated context (BarJsonSerializerContext) should handle FooValue and BarValue.

Actual behavior

The generated context (BarJsonSerializerContext) handles only BarValue.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions