MethodBase.Invoke Method
.NET Framework 4
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 | |
|---|---|---|
|
Invoke(Object, Object[]) | Invokes the method or constructor represented by the current instance, using the specified parameters. |
|
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) | When overridden in a derived class, invokes the reflected method or constructor with the given parameters. |
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)
- 3/16/2012
- Ken Birman
- 3/17/2012
- Ken Birman