I am trying to construct an instance of a generic type and call a method on that instance. Then return the result of the method.
var genericType = typeof(GenericType<>).MakeGenericType(typeof(TOutput));
il.DeclareLocal(genericType);
var instanceMethod = genericType.GetMethod("MethodName", new Type[0]);
il.Emit(OpCodes.Call, instanceMethod);
il.Emit(OpCodes.Ret);
I keep getting a 'System.InvalidProgramExecution' exception.
GenericType class looks like this
public class GenericType<T>
{
public T MethodName()
{
...
}
}
Try this code: