This is because the method name is not "M" , it will be "YourNamespace.SomeBase.M" . Therefore, either you will need to specify this name (along with the corresponding BindingFlags ), or instead get the method from the interface type.
So, the following structure is given:
namespace SampleApp { interface IFoo { void M(); } class Foo : IFoo { void IFoo.M() { Console.WriteLine("M"); } } }
... You can do it:
Foo obj = new Foo(); obj.GetType() .GetMethod("SampleApp.IFoo.M", BindingFlags.Instance | BindingFlags.NonPublic) .Invoke(obj, null);
... or that:
Foo obj = new Foo(); typeof(IFoo) .GetMethod("M") .Invoke(obj, null);
source share