Uh oh!
There was an error while loading. Please reload this page.
Fix STJ support for System.Reflection.NullabilityInfoContext.IsSupported = false - #102852
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
Uh oh!
There was an error while loading. Please reload this page.
…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. |
MichalStrehovsky
commented
May 30, 2024
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.) |
eiriktsarpalis
commented
May 30, 2024
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. |
MichalStrehovsky
commented
May 30, 2024
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. |
eiriktsarpalis
commented
May 30, 2024
OK, I've pushed a change that reinstates the exception when the user has opted into enforcement. |
Uh oh!
There was an error while loading. Please reload this page.
…ion/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs
eiriktsarpalis
commented
May 30, 2024
/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>
jeffhandley
commented
Aug 31, 2025
/backport to release/8.0-staging |
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/17358950692 |
@jeffhandley backporting to "release/8.0-staging" failed, the patch most likely resulted in conflicts: $ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix STJ support for System.Reflection.NullabilityInfoContext.IsSupported = false
Using index info to reconstruct a base tree...
M src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs
M src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/OptionsTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs
Auto-merging src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/OptionsTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/OptionsTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix STJ support for System.Reflection.NullabilityInfoContext.IsSupported = false
Error: The process '/usr/bin/git' failed with exit code 128Please backport manually! |
Fix#102848