Exception has been thrown by the target of an invocation


More C# Resources

You may receive this exception when you use the Invoke() method (of a form perhaps). The cause of this exception is another exception which occured inside the method being invoked.
Since you don’t know what actually went wrong inside the method that was being invoked, we will need to get the inner exception of the method.
Suppose we have the following line which invokes a method:

MyForm.Invoke(MyForm.MyDelegate, new Object[] { someParameter });

To catch the exception, enclose the line within a try/catch block and get the InnerException:

MyForm.Invoke(MyForm.MyDelegate, new Object[] { someParameter });
catch (Exception ex)

This should show you the actual exception message inside a message box.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top