Friday, May 16, 2008

"Exception has been thrown by target of invocation" Error

You might face this error and wonder what happened. I had a similar situation today. The code was working fine and all of a sudden I got this error. I am not that kind of person who beleives very strongly that all errors are due to some bad coding, maybe by the developer or maybe thrown bt the tools used for development. Till now, whenever I have been involved in coding or debuging someone's problem , I have managed to at least find out where the issues have been and most of time solve it too. Anyway, so I started tracing my steps backwards and commenting recenlty changed codes. But still was not able to find exactly where the error is occuring.

Finally, during one my debug attempts, I happened to look at the exception object's inner exception and noticed the error was because of a new addition I had on the app.config file. I made the correction and the error was gone. BTW, the change I did was add a "configSections" tag at the end of the app.config file. If you add a "configSections" tag, it has be the first line after the "configuration" tag.

So to conclude, if you get this error ""Exception has been thrown by target of invocation"", look at the inner exceptions. Keep looking recursively into the inner exception's "inner exception" till you see "nothing" and hopefully you see the actual error message and correct the problem.

happy coding !!

No comments:

Post a Comment