Runar Ovesen Hjerpbakk

Software Philosopher

Exception has been thrown by the target of an invocation

Exception has been thrown by the target of an invocation

This was the message that greeted me when I tried running my tests from Visual Studio 2010 this morning. Changing solution to run other tests did not help, neither did restarting Visual Studio. Next, I tried to run the tests manually using mstest from the command line. The tests ran successfully. How to get the tests running from Visual Studio again?

After a little googling, the Internet presented me with a few suggestions for solving the problem. No one seemed sure of the cause, and I not sure what caused my problem. However, I will present the “solutions” in the order of which I tried them, plus some suggestions that were not necessary in my situation.

1. The number one cause around the web was that Team Explorer was not connected to the Team Foundation Server. In my case, Team Explorer was already connected when the problem first appeared, but I tried to reconnect nevertheless. No luck.

2. Next, I tried to reinstall Team Explorer. This is a quick reinstallation, but it did not solve the problem.

3. My third try was to reset all Visual Studio settings back to defaults. Remember to export your existing settings before you try this. The command is

devenv /resetuserdata

and it will reset Visual Studio back to its original self. This solved the problem and the error message did not reappear when I tried running my tests. The exact cause might never be known, but after a few minutes of customization, I had a fully functional IDE again.

4. The fourth and untried suggestion was to reinstall Visual Studio 2010 SP1…

5. … and finally: reinstall Visual Studio.