How to debug System.TypeLoadException errors in .NET?

kertosis picture kertosis · Apr 17, 2011 · Viewed 58.3k times · Source

I'm getting the following error on one of my referenced assemblies:

Could not load type 'System.Func`2' from assembly 'MyAssembly, ...

I'll be honest, I don't think I can remember the last time I saw a System.TypeLoadException error, or if I saw it, the solution was obvious. My first instinct was to see what MSDN had to say about it:

TypeLoadException is thrown when the common language runtime cannot find the assembly, the type within the assembly, or cannot load the type.

Perhaps I'm reading this wrong, but it is saying that the CLR simply can't find the type? That might make more sense if this wasn't something that was in mscorlib. This was all built ontop of .NET4 with VS2010, so there's no mono or other weird library issues. Am I over thinking this? What's going on?

Answer

Ian Warburton picture Ian Warburton · Mar 13, 2014

I received this error after refactoring. I had two projects compiling to DLLs with the same name.

Check the "Assembly name" in the project's properties' "Application" section.