-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Support resolving metadata tokens in MetadataLoadContext #87657
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsWhen using MetadataLoadContext, This is inconvenient for advanced reflection scenarios. For example, if you are scanning IL code (perhaps retrieved using I do not think there is a technical reason that prevents these methods from working. If everything looks OK with this idea then I am happy to implement these.
|
Thoughts @buyaa-n @jkotas @AaronRobinsonMSFT? MLC does do internal resolution of some of those here: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Ecma/EcmaResolver.cs |
I don't see anything wrong with this. There are going to be tricky parts, for example if EnC is involved. However, for assemblies defined with RefEmit or for statically loaded assemblies this seems like a reasonable feature. |
It should be very straightforward to implement these methods. @reflectronic Are you interested in submitting a PR? |
EnC/S.R.E/etc. don't matter for MLC, right? It just loads assembly files from disk using S.R.M, there's no runtime magic involved. The APIs already exist and work for And I can see why Ati chose not to implement them; the logic is complicated and the layering of MLC doesn't lend itself to these APIs. I already have some code written for this, but I'm not really happy with how it looks, so I'll see if I can refactor it and put up a PR. I don't know if I am overthinking it or if there's something we can change to make it easier. |
Files on disk can have EnC delta tables and since MLC also accepts a |
The existing MetadataLoadContext code deals with the token resolution internally. The fix for this issue should just wire-up the existing internal token resolution to the public APIs. I would not worry too much about following all the existing abstractions. It is ok for this fix to cut corners around the abstractions. The fix for this issue should not be improving the internal token resolution to handle EnC data formats, etc. Improvements like this should be tracked by new issue and fixed by separate PRs. |
Right, I agree that for TypeRef it is very easy because MLC has the code to resolve them. To my knowledge, it does not have the code to generally resolve MemberRefs, because that never comes up in reflection. This is the harder part. There is this bit in custom attribute parsing: Lines 69 to 81 in bced584
But this approach is not suitable for general signature matching. For example, it does not work for methods overloaded by return type (it's not relevant here since constructors always return I agree that handling EnC tables is a separate feature. MLC ignores them entirely right now, it would be weird to handle them just for this. |
You are right - MemberRefs would need work. |
When using MetadataLoadContext,
Module.{ResolveType,ResolveMember,ResolveMethod,ResolveField,ResolveSignature,ResolveString}
all throw NotSupportedException.This is inconvenient for advanced reflection scenarios. For example, if you are scanning IL code (perhaps retrieved using
MethodBody.GetILAsByteArray
), these methods are the only way to resolveMemberRef
s andTypeRef
s used in IL.I do not think there is a technical reason that prevents these methods from working. If everything looks OK with this idea then I am happy to implement these.
The text was updated successfully, but these errors were encountered: