This topic has not yet been rated - Rate this topic

MethodBase.Invoke Method

Invokes the method or constructor reflected by this MethodInfo instance.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method Invoke(Object, Object[]) Invokes the method or constructor represented by the current instance, using the specified parameters.
Public method Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) When overridden in a derived class, invokes the reflected method or constructor with the given parameters.
Top
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Undesirable behavior: Captures exceptions, rethrows them as System.Reflection.TargetInvocationExcept
The .Invoke methods (including DynamicInvoke) have an undesirable behavior: when running directly in the CLR (as opposed to within Visual Studio), if an application throws an exception in the context of a .Invoke, the .Invoke catches the exception (no matter what kind) and then rethrows it as the inner exception of a System.Reflection.TargetInvocationException, which will be unhandled and hence causes the application to terminate.  If you attach a debugger at this point, the stack will have been unwound, hence you can obtain the line number at which your exception occured, and also the cause, but won't be able interrogate local variables or see the arguments to the methods that were called.  To avoid this, cast to dynamic, as in: ((dynamic)Foo).Invoke(args)