-
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
Fix issues related to JsonSerializerOptions mutation and caching. #65863
Fix issues related to JsonSerializerOptions mutation and caching. #65863
Conversation
Added When you commit this breaking change:
Tagging @dotnet/compat for awareness of the breaking change. |
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsSupersedes #65799. After conversation with @layomia in #65799 (comment) I realized that the caching implementation introduced in #64646 contains a bug. More specifically, a locked/immutable
Both of these changes alter the
|
25f9632
to
40cf07a
Compare
...ries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
...ries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs
Show resolved
Hide resolved
...Json/tests/System.Text.Json.Tests/Serialization/CustomConverterTests/CustomConverterTests.cs
Show resolved
Hide resolved
…tnet#65863) * Fix issues related to JsonSerializerOptions mutation and caching. * fix test style * fix linker warning
Apologies for that, I've reposted the changes in #66248 with relevant tests disabled in netfx. |
I'm removing the breaking-change label since in hindsight, the removed behavior (i.e. ability to add a |
Supersedes #65799. After conversation with @layomia in #65799 (comment) I realized that the caching implementation introduced in #64646 contains a bug. More specifically, a locked/immutable
JsonSerializerOptions
instance can still be mutated by the serialization infrastructure in couple of important ways:JsonSerializerContext
field._typeInfoCreationFunc
field if the options instance has been passed to a reflection serialization API.Both of these changes alter the
JsonTypeInfo
resolution semantics in important ways, and as such they can invalidate the current contents of the metadata cache. This PR makes the following changes:JsonSerializerContext
values can now only be attached to mutableJsonSerializerOptions
instances. This is a potential breaking change, however the new throwing behavior is arguably better than the current one (nondeterministic use of serialization metadata).IsInitializedForReflectionSerializer
an instance method instead of a static, and ensure it gets propagated correctly to shared caching contexts.I ran the benchmark suite and no performance regressions were recorded.