Skip to content

Conversation

@ericstj
Copy link
Member

@ericstj ericstj commented Jan 6, 2022

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.

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.
@ghost
Copy link

ghost commented Jan 6, 2022

Note regarding the new-api-needs-documentation label:

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.

@ghost ghost assigned ericstj Jan 6, 2022
@ghost
Copy link

ghost commented Jan 6, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: ericstj
Assignees: -
Labels:

area-System.Text.Json, new-api-needs-documentation

Milestone: -

<Import Project="System.Text.Json.TestLibrary.targets" />

<ItemGroup>
<ProjectReference Include="..\..\gen\System.Text.Json.SourceGeneration.Roslyn3.11.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
Copy link
Member Author

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.

Copy link
Member

@eerhardt eerhardt left a 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.

…neration.Tests/NETStandardContextTests.cs

Co-authored-by: Eric Erhardt <[email protected]>
@ericstj ericstj merged commit 0b91bea into dotnet:main Jan 7, 2022
@ericstj
Copy link
Member Author

ericstj commented Jan 7, 2022

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2022

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1669729149

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2022

@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 128

Please backport manually!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

2 participants