dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

MethodBase.Invoke can resolve overrides?

Open rawling opened this issue 11 months ago • 0 comments

Type of issue

Other (describe below)

Description

The article says

Note that you cannot use the MethodInfo object from the base class to invoke the overridden method in the derived class, because late binding cannot resolve overrides.

I don't get this behaviour. If I call GetMethod on the type of a base class, and then Invoke with an instance of a derived class that overrides the method, I get the overridden result.

I have to call .MethodHandle.GetFunctionPointer and then Activator.CreateInstance if I want to force a call to the base implementation on a derived instance, as per http://stackoverflow.com/questions/4357729/ddg#14415506

Is the documentation wrong, or have I misunderstood it?

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.invoke?view=net-9.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Reflection/MethodBase.xml

Document Version Independent Id

52226c0f-7dec-ed01-fb7a-4a5250bbff56

Article author

@dotnet-bot

rawling avatar Feb 05 '25 15:02 rawling