Search code examples
c#.netreferenceassembliestypeloadexception

How can I troubleshoot : System.TypeLoadException?


Can you show me a way to troubleshoot System.TypeLoadException ?

I am having this exception for an existing project in my solution which I reference from a unit test project in the same solution.

This exeption is thrown when I run my unit tests. They fail because of this exception:

Details:

Test method MyErrorHandler.Test.MyTest.Parse_RecievesValidMessage_ReturnsArray threw exception: System.TypeLoadException: Could not load type 'MyTestNameSpace' from assembly 'MyTestAssemblyName.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=Somenumber.

What should I check or where should I start to investigate?


Solution

  • In the exception message, or maybe in an InnerException property, you might find what was the requested type, with the fully qualified name, version, assembly. Check if the given assembly is reachable from the application directory. Reachable meaning in the application directory or in the private probing path of the application.

    EDIT : also check that satellite assemblies (referenced by the assembly that the type loader fails loading) are reachable.