What could be causing a System.TypeLoadException in a Visual Studio Unit Test?

Jay Sullivan picture Jay Sullivan · Apr 20, 2011 · Viewed 46.5k times · Source

I've got a C# .NET class library MyClassLibrary that compiles fine. I'm trying to create a unit test project for it (using Visual Studio Unit Testing Framework, with Visual Studio 2010). The class library does have big classes in it, but whenever I run even the simplest test against the simplest class, I get the following exception:

Test method MyClassLibraryTest.MyClassLibraryTests.MySimpleClassTest threw exception: System.TypeLoadException: Could not load type 'MyClassLibrary.MySimpleClass' from assembly 'MyClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

All of the projects I'm dealing with are in the same solution, and all are compiled for .NET 4.0. All of this is on a Windows 7 64-bit machine.

Here's the weird part: when I "Run" the test, I get the above error. But when I "Debug" the test, it runs fine. Why?

Answer

Amir Abiri picture Amir Abiri · Feb 21, 2013

I just banged my head against this one for an hour. The problem was that I had a command line project named Something.exe, which was using a class library project named Something.dll.