Resolving generic type creates Scope System.Private.CoreLib resulting in MissingMethodExceptions
See original GitHub issueThe following generic type:
TypeReference genericType = module.ImportReference(typeof(System.Runtime.CompilerServices.TaskAwaiter<>))
(where module is a loaded Net5.0 assembly) The typeDef Scope is set to System.Private.CoreLib.dll
which seems broken because when I try and call a method on this type I get MissingMethodException.
When I import a type that returns one of these generics the Scope on that return type is System.Runtime
:
Interestingly the loaded assembly that contains this module has the following cached referenced assemblies, which do include System.Private.CoreLib even though ilspy does not show this dependency.
This is what I see in ilspy:
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
System.MissingMethodException: Method not found ...
This error occurs when you have different versions of EntityFrameworkCore and NetCore in your project, please be sure to install the version ...
Read more >Type.MakeGenericType(Type[]) Method (System)
The following example uses the MakeGenericType method to create a constructed type from the generic type definition for the Dictionary<TKey,TValue> type.
Read more >Troubleshooting the CLR
There is a generic type ( GenericIn ) which implements a generic interface ( IGenericIn ) with a non-generic method ( DoSomething )....
Read more >Deserialization of generic types fails due to inability to find ...
Bug description A generic type containing properties with an init accessor fails to serialize. Repro steps This type fails to serialize with ...
Read more >Generating Swagger example requests with Swashbuckle
BadRequest, Type = typeof (ErrorsModel), Description = "An invalid or missing input parameter will result in a bad request" )].
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, I skipped a bunch of other rewrite logic for variables, etc. So wow your code is much simpler, thanks and all my tests are still passing. I seemed to have gone off into the weeds with bugs I was running into thinking I had to also “make” all the types referenced by the generic (method parameter types and return types and so on). But somehow your magic avoids all that and things still seem to work… thanks for taking the time to help me out!
@ltrzesniewski that’s likely the case, but if you execute the Cecil code and the patched code on the same framework (net50 here), I think you could expect the
SR
overloads to work.