-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
System.MissingMethodException: Method not found: 'Void System.Text.Json.Serialization.Metadata.JsonObjectInfoValues1.set_ObjectCreator(System.Func
1<!0>)'. with .NET Standard 2.0
#61737
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsDescriptionI have a .NET 6 app that references a .NET Standard 2.0 class library, which in turn uses the new System.Text.Json source generator to speed up serialization. When running I get the following exception (this stack trace is from a project used to reproduce the error):
This DOES not happen if the class library targets .NET 6. Reproduction StepsI've created a sample to reproduce this so I could eliminate the possibility of something being wrong with the original projects (upgraded from .NET 5). The class library (netstandard2.0) code:
The console app (net6.0) code:
Expected behaviorThis should work exactly the same in .NET 6 and .NET Standard 2.0, given that the System.Text.Json is multi-targeting. Actual behaviorIt fails in .NET Standard 2.0 with the exception above. Regression?No response Known WorkaroundsNo response Configuration.NET 6.0.100 Other informationNo response
|
Can you share the repro project? I tried to repro and it worked for me: https://github.com/ericstj/sample-code/tree/jsonRepro61737/jsonRepro61737 |
This issue has been marked |
@ericstj yours is working because the client lib targets .net 6, not .net standard 2.0. See here please: https://github.com/hugoqribeiro/trial-n-error/tree/main/System.Text.Json.Issue.61737 |
I can reproduce -- see here for a minimal repro without sourcegen. The issue reproduces with This seems related to exposing init-only properties in netstandard2.0 TFMs. When
whereas in the
I suspect that the runtime cannot bind to the right method because the modifier types don't match. Related to dotnet/roslyn#45510 |
Oops, my apologies. Further illustration that repro projects are good to share so we can see the problem ;) Excellent find by the way, this is a very interesting and subtle bug.
Interesting. @eiriktsarpalis could you try explicitly adding a type-forward in the 6.0 build of System.Text.Json for this type and see if it resolves the issue? It's curious that the compiler leaks knowledge of this internal type to customer assembly. That feels like a violation of the visibility contract (and might require us to add a check for this to our API compat infra cc @safern). runtime/src/libraries/Common/src/System/Runtime/CompilerServices/IsExternalInit.cs Lines 16 to 20 in e9036b0
I'd be curious what @jaredpar thinks about the compiler emitting a reference to an internal type here. |
This is an interesting scenario, that we should definitely explore guarding on API Compat. |
Pending @jaredpar's comment on the validity of compiler behavior here, I could imagine an effective visibility rule in API Compat as: |
This is a hole we missed with |
I don't quite understand the details. I've make a repro to test the .NET Standard 2.0 JsonContext running in .NET 6.0 and .NET Framework 4.8 test project. The result is strange to me.
For the clue of The result means I need to add .Net Standard 2.0 |
I've changed my repro to make sure the |
Reopen for servicing |
Addressed in 6.0 by #63520. |
Description
I have a .NET 6 app that references a .NET Standard 2.0 class library, which in turn uses the new System.Text.Json source generator to speed up serialization.
When running I get the following exception (this stack trace is from a project used to reproduce the error):
This DOES NOT happen if the class library targets .NET 6.
Reproduction Steps
I've created a sample to reproduce this so I could eliminate the possibility of something being wrong with the original projects (upgraded from .NET 5).
The class library (netstandard2.0) code:
The console app (net6.0) code:
Expected behavior
This should work exactly the same in .NET 6 and .NET Standard 2.0, given that the System.Text.Json is multi-targeting.
Actual behavior
It fails in .NET Standard 2.0 with the exception above.
Regression?
No response
Known Workarounds
No response
Configuration
.NET 6.0.100
Visual Studio 2022 17.0.1
Windows 10 20H2
Other information
No response
The text was updated successfully, but these errors were encountered: