question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolving generic type creates Scope System.Private.CoreLib resulting in MissingMethodExceptions

See original GitHub issue

The 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:

image

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.

image

This is what I see in ilspy:

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lovettchriscommented, Jun 22, 2021

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!

1reaction
jbevaincommented, Jun 15, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found