-
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
[release/7.0] Disable nullability warnings in JSON source generator #74861
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsBackport of #74801 to release/7.0 /cc @eiriktsarpalis @krwq Customer ImpactTestingRiskIMPORTANT: Is this backport for a servicing release? If so and this change touches code that ships in a NuGet package, please make certain that you have added any necessary package authoring and gotten it explicitly reviewed.
|
@carlossanlop I'm guessing this does not apply to RC fixes right? |
Approved, we would potentially service for it. |
#nullable enable | ||
|
||
#nullable enable annotations | ||
#nullable disable warnings |
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.
Are we ever generating public API? With annotations enabled we will still be outputting nullability metadata, and if we have reason to believe that the annotations are incorrect, that'll mean incorrect nullability information surfaced to consumers of the APIs.
If this is all internal to the assembly, it's probably fine. If it's not, we might instead consider doing:
#nullable disable
#pragma warning disable CS8632
instead, or something along those lines.
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.
@eiriktsarpalis do you want to resolve this question before I hit merge?
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.
Yes let's please resolve this q first.
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.
we do produce some public APIs - AFAIK they're correct though
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.
they're correct though
Ok
Correct, not needed for RCs. |
@@ -112,6 +112,10 @@ | |||
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" /> | |||
</ItemGroup> | |||
|
|||
<ItemGroup> | |||
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Primitives\src\Microsoft.Extensions.Primitives.csproj" /> |
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.
This doesn't feel right to me. I know these are tests, but having something in System
depend on things in Microsoft.Extensions
feels backwards.
Is there something about StringValues
that we can isolate into a unit test type? Or do we actually have to use the StringValues
type in order to test the scenario?
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.
StringValues is what customer reported so it was added here as a test to make sure that specific scenario works. I think that should be fine for tests, we already depend on other things like JSON.NET
Backport of #74801 to release/7.0
/cc @eiriktsarpalis @krwq
Customer Impact
Customers have reported that certain nullability annotations cause JSON source-gen to generate code which produce code with warnings. Some libraries (i.e. Microsoft.Extensions.Primitives) added nullability annotations to their libraries and customers upgrading now start seeing nullability warnings. This is super annoying for users as they cannot suppress them in the source code and in certain situations where treating warnings as errors is enabled may cause build errors.
While this is not a regression in JSON itself, combination of this bug with new nullability annotations is a regression from product perspective.
Related issues:
StringValues
withJsonSerializerContext
produces warnings with7.0.0-preview*
#74652Testing
Customer reported scenarios are added as tests, existing scenarios are already tested.
Risk
Minimal - product change is limited to disabling nullability warnings in the generated code.
IMPORTANT: Is this backport for a servicing release? If so and this change touches code that ships in a NuGet package, please make certain that you have added any necessary package authoring and gotten it explicitly reviewed.