-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Type.GetInterfaceMap doesn't work for all cases #89157
Comments
I've looked into this and discovered two issues:
|
For 2, I'm surprised it doesn't just crash - we're asking for a method invoker of an uninstantiated method, basically (the interface methods returned from GetMethods are uninstantiated). I don't know if there's a easy way to solve this. We could do MakeGeneric, but that might end up throwing if the code doesn't exist. |
That's what's happening in 1), in 2) we're having actually instantiated methods because they're being retrieved from interface IGenericInterface<T>
{
void Method(T arg);
}
var ifaceMethod = typeof(IGenericInterface<object>).GetMethod("Method"); // Void Method(System.Object)
var invoker = (VirtualMethodInvoker)GetMethodInvoker(ifaceMethod);
IntPtr classRtMethodHandle = invoker.ResolveTarget(instanceType.TypeHandle);
MethodBase methodBase = RuntimeAugments.Callbacks.GetMethodBaseFromStartAddressIfAvailable(classRtMethodHandle); // Void Method(T) |
MethodBase.GetMethodFromHandle has two overloads to combat the issue with generic sharing - maybe there's something in the implementation of it that we could leverage (I haven't actually looked though). |
If/when this is fully implemented, we also need to make sure reflection-visibility of the interface method also ensures reflection-visibility of the implementation method. There won't be anything in the compiler to ensure the target methods are reflection visible. Note that doing this for everything is a size regression so we should make sure compiler only makes targets reflection-visible if GetInterfaceMap is actually called. Nobody actually calls this API. |
It only works for the most straightforward cases. See failing System.Runtime tests blocked on this issue.
The text was updated successfully, but these errors were encountered: