Skip to content

Conversation

@lfpraca
Copy link

@lfpraca lfpraca commented Oct 30, 2025

Clarify source generation limitations regarding reference preservation in deserialization.


Internal previews

📄 File 🔗 Preview link
docs/standard/serialization/system-text-json/reflection-vs-source-generation.md Reflection versus source generation in System.Text.Json

Clarify source generation limitations regarding reference preservation in deserialization.
@lfpraca lfpraca requested review from a team and gewarren as code owners October 30, 2025 12:43
@dotnetrepoman dotnetrepoman bot added this to the October 2025 milestone Oct 30, 2025
@dotnet-policy-service dotnet-policy-service bot added dotnet-fundamentals/svc community-contribution Indicates PR is created by someone from the .NET community. labels Oct 30, 2025
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not entirely accurate, reference preservation is not supported when constructor parameters are present in general. This is because of a fundamental bootstrapping issue, you can't create a constructor parameter that contains a circular reference to the constructed value if the value hasn't been constructed yet.

The source generator specific issue is that init and required members are encoded as constructor parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants