I was leading a lab today. The first exercise has a starting solution with some basic code that you are suppose to enhance during the implementation. One of the very first thing you shall do is to run the unit tests to make sure that the code works. It has always worked! That is, until today. One of the participants couldn’t execute any of unit tests. Visual Studio kept on displaying the same error message for every attempt to run any of the unit tests: “Exception has been thrown by the target of invocation”.
We searched on the Internet and found many suggestions on what might cause the problem. Finally we found out that the reason was that his development environment wasn’t connected to TFS. The lab is of course checked into TFS and there is a bug in VS 2008 that causes this problem if you open a bounded solution in a studio disconnected from TFS (http://blogs.msdn.com/b/shitals/archive/2009/12/31/9942725.aspx).