locked
Exception has been thrown by the target of an invocation

    Question

  • Hi,

    I am getting an error message "Exception has been thrown by the target of an invocation" when my application is loading a vb.net 2005 form.

    I am using vb.net 2005 with SP1, and framework version v2.0.50727

     

    Any idea what could be causing this?

     

    Thanks

    Thursday, February 01, 2007 2:32 PM

Answers

  • When the exception is thrown and caught in the IDE, check the InnerException property.  Please post the name, message and stack trace of the inner exception as that's going to provide the most information about the problem.
    Thursday, February 01, 2007 4:41 PM

All replies

  • This is usually the exception you get when a constructor throws an exception.

    Try catching the exception.  You usually get some more extended information on what exception was thrown etc.

    Thursday, February 01, 2007 4:05 PM
  • This is thrown by the constructor, when calling InitializeComponent() routine.

    However, thats all the information I am getting.

    I did a cleanbuild and then a build, and it builds fine. But I still get the error, when I run the app.

    This is a windows application, in vb2005 with SP 1

     

    Any thoughts?

    Thursday, February 01, 2007 4:24 PM
  • Have you tried stepping through the InitializeComponent routine to see where it fails?

    I'd have to edge my bets that it probably stems from an out of date reference of some kind. 

    Thursday, February 01, 2007 4:32 PM
  • When I step thru the code, it doesnt actually go inside InitializeComponent(), the procedure for that resides in the designer.vb page.

    Are you saying that a component may be outdated?

    Never came across anything like that in the past, but I have tried checking for out of date references, but cant find anything.

    Thursday, February 01, 2007 4:40 PM
  • When the exception is thrown and caught in the IDE, check the InnerException property.  Please post the name, message and stack trace of the inner exception as that's going to provide the most information about the problem.
    Thursday, February 01, 2007 4:41 PM
  • You can still access the InitializeComponent method .. your form is a partial class and the method is hidden by default.

    You'll probably find it is decorated with a DebuggerStepThrough style attribute, hence why you do not normally step into it.  Remove it and you should be ok to step in at runtime.

    Thursday, February 01, 2007 4:59 PM
  • ok, the part of checking the InnerException property helped big time. The problem was resolved. I had added a project to my solution, and an assembly of the new project was being referenced. That assembly could not be found. So I created that.

    However, I would like to clarify something for my own information.

    Currently I have a solution file, that contains 5or 6 projects within the solution file. I add an existing project to my solution file, do a clean build (of the solution), then do a build (of the solution), and then do a "rebuild the solution". Shouldnt that process create the required assemblies of the projects within my solution?

    Or do I have to manually create the assemblies, every time I add an existing project to my solution?

     

    Thanks very much for everybody's help.

    Thursday, February 01, 2007 5:25 PM
  • I get the following error when trying to run the Unit tests in VS 2008 for a VB.NEt solution:

    Exception has been thrown by the target of an invocation.

    Please help if anyone has faced this issue earlier ?

    Thursday, August 16, 2012 10:11 AM