Context
I want to make this call via reflection
instanceOfEventPublisher.Publish<T>(T eventInst);
When I call
`
private void GenCall(IEventPublisher eventPublisher, object theEventObj){
var thePublisher = eventPublisher.GetType();
thePublisher.InvokeMember(
"Publish",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
eventPublisher,
new object[] {theEventObj}
);
}
`
I get:
System.MissingMethodException: Method ‘EventAggregator.EventPublisher.Publish’ not found.
How to call the generic ?
You might have to do
GetMethods()and search for the “Publish”MethodInfo. Or if “Publish” isn’t overloaded you might get away with justGetMethod("Publish"). In either case, you’ll need to callMakeGenericMethod()on theMethodInfoto add your type arguments.