Click here to Skip to main content
15,356,705 members
Please Sign up or sign in to vote.
1.40/5 (3 votes)
See more: , +
I have a winforms application which was working fine. Recently i formatted my system and reinstalled VS 2008. From that time the application has stopped running.
When i run it through VS it gives error

"exception has been thrown by the target of an invocation."

I went on to debug and found that in the this exception comes when from c# code using reflection the code tries to invoke a function from an assembly which is written in c++.
Updated 24-Oct-19 2:45am
Member 11698388 28-Oct-17 7:27am

Eventually I solved this myself. It was just a matter of getting to the root of the problem.
Actually the cuase of this exception was another exception which occured inside the method being invoked.

So i went to look out for solution by searching the exception ex.innerexception .
From there i searched the stack trace of that exception to finnaly get to the root of the problem.

So anyone getting this error do look for the innerexception cause the real problem lies there.

Nelek 16-Mar-12 14:45pm
Thank you for posting your own solution. 5 for it
Basics Learner 16-Aug-13 7:01am
Thanks saved me !
thams 24-May-12 0:59am
Thanks a ton. Saved me lot of time. Just went to the inner exception and found the problem. My problem is with threading. Thanks again.
MAYANK GEETE 11-Sep-13 6:33am
I am New To WPF and i am working on it but it gives the same error "Exception has been thrown by the target of an invocation." it is a simple program to show data (that is stored in database) to datagrid in wpf. can u plz help?
thanks in advance
Member 14851467 9-Jun-21 8:40am
Thank you. Your solution worked for me too. I previously was running a code synchronously and decided to change it and run in async mode because I added an activity indicator to display while the task is going on; only for my codes to start generating errors.
Member 10954869 20-Aug-14 3:32am
i got inner exception is null why and what the problem
Umer Asif 22-Mar-15 7:14am
so what you did after finding the Exception??
Renato L. Carvalho 17-Jul-15 8:44am
Thank You!!
CihanOz 12-Apr-17 15:49pm

I had my mistake web.config settings. I solved the problem!
HardikPatel.SE 8-Aug-17 6:41am
Also you can use "ex.GetBaseException()" which will return you the root exception message.
Disable the ajax for a moment (EnablePartialRendering="false" on the scriptmanager).

we Got Exception aftr that delete EnablePartialRendering property.
Great said by Mateen Khan, you need to understand what is you controls default value..

eg i'm using combobox in silverlight and i was trying to bind its selected index

as a default its selected index was -1

but it was get nothing from the respective property ...

I looked inside the inner exception and find out my solution
Thomas Daniels 21-Dec-12 8:39am
Why do you answer to a question from May? The question is solved already, and the question has an accepted answer.
Elegantly Wasted 17-Oct-13 6:54am
sharing my views..... thats it.... -_-

actually the solution helped me indeed... i just tried to tell what i came accross....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900