-
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 STJ support for System.Reflection.NullabilityInfoContext.IsSupported = false #102852
Fix STJ support for System.Reflection.NullabilityInfoContext.IsSupported = false #102852
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/OptionsTests.cs
Show resolved
Hide resolved
…rialization/OptionsTests.cs
I do not think that this is the right fix. I think the right fix is to throw exception when RespectNullableAnnotations = true and the nullability annotations are trimmed. |
I think I know the answer, but just to double check - when using the source generator, this runtime reflection doesn't happen, right? (I.e. wasm is only running into this because it's using trimming in a way that we do not recommend to anyone.) |
It's something I considered, although ultimately I settled on the conclusion that it's common for reflection to misreport metadata in the context of trimmed applications. If anything, the current throwing behavior of
That is correct, which is why I'm not particularly concerned about this corner case. There will have been warnings. |
The current NullabilityInfoContaxt feature switch is simply a bad design. We knew that it would be bad when it was introduced (#55860 (comment)). I was not involved in any of the discussions besides what I posted so I don't know what tradeoff forced going with it anyway, despite being bad.
There will be no warnings: Blazor WASM that hit this turns them off (that's why people are not guided towards using the source generator in the first place). If we are choosing between an exception and silent different behavior, we should choose the exception be default and only very exceptionally silent different behaviors. |
OK, I've pushed a change that reinstates the exception when the user has opted into enforcement. |
...Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs
Outdated
Show resolved
Hide resolved
…ion/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs
/backport to release/9.0-preview5 |
Started backporting to release/9.0-preview5: https://github.com/dotnet/runtime/actions/runs/9302780301 |
…ted = false (dotnet#102852) * Fix STJ support for System.Reflection.NullabilityInfoContext.IsSupported = false * Update src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/OptionsTests.cs * Bring back exception in cases where RespectNullability has been turned on. * Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs --------- Co-authored-by: David Cantú <dacantu@microsoft.com>
Fix #102848