-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix NETStandard library using JSON source gen #63472
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
Conversation
NETStandard libraries using JSON source gen would fail to load on .NETCore due to missing IsExternalInit in the assembly. On .NETCore this is defined, whereas on .NETStandard JSON carries an internal copy. The compiler emits references to the internal type when a NETStandard library calls init-only setters in JSON types, but these references are not satisfied when the library runs on .NETCore. Fix this by adding a type forward to JSON for the IsExternalInit type.
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsFixes #61737 NETStandard libraries using JSON source gen would fail to load on On .NETCore this is defined, whereas on .NETStandard JSON carries an Fix this by adding a type forward to JSON for the IsExternalInit type.
|
| <Import Project="System.Text.Json.TestLibrary.targets" /> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\gen\System.Text.Json.SourceGeneration.Roslyn3.11.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> |
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.
I could have chosen just 1 copy of the generator to use, or even just checked in the generated code, but I created a parallel structure in case you find it interesting to add more tests. Let me know if you think this is overkill.
eerhardt
left a comment
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 LGTM. I had some nits and questions.
...es/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/NETStandardContextTests.cs
Outdated
Show resolved
Hide resolved
...son/tests/System.Text.Json.SourceGeneration.TestLibrary/System.Text.Json.TestLibrary.targets
Show resolved
Hide resolved
...es/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/NETStandardContextTests.cs
Outdated
Show resolved
Hide resolved
…neration.Tests/NETStandardContextTests.cs Co-authored-by: Eric Erhardt <[email protected]>
|
/backport to release/6.0 |
|
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1669729149 |
|
@ericstj backporting to release/6.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix NETStandard library using JSON source gen
Using index info to reconstruct a base tree...
M src/libraries/System.Text.Json/ref/System.Text.Json.csproj
M src/libraries/System.Text.Json/src/System.Text.Json.csproj
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Text.Json/src/System.Text.Json.csproj
CONFLICT (content): Merge conflict in src/libraries/System.Text.Json/src/System.Text.Json.csproj
Auto-merging src/libraries/System.Text.Json/ref/System.Text.Json.csproj
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix NETStandard library using JSON source gen
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128Please backport manually! |
Fixes #61737
NETStandard libraries using JSON source gen would fail to load on
.NETCore due to missing IsExternalInit in the assembly.
On .NETCore this is defined, whereas on .NETStandard JSON carries an
internal copy. The compiler emits references to the internal type when
a NETStandard library calls init-only setters in JSON types, but these
references are not satisfied when the library runs on .NETCore.
Fix this by adding a type forward to JSON for the IsExternalInit type.