如何调试在.NET System.TypeLoadException错误?

问题描述:

我得到在我引用的程序之一以下错误:

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

无法加载类型System.Func`2从程序集MyAssembly程序,...

我会说实话,我不认为我能记得上一次我看到一个System.TypeLoadException错误,或者如果我看见了,该解决方案是显而易见的。我的第一反应是看看有什么 MSDN不得不说一下的:

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被抛出时,
  公共语言运行时无法找到
  装配,内部类型
  组装,或无法加载类型。

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

也许我读这个错误,但它说,CLR根本找不到的类型?这可能更有意义,如果这不是东西,是在mscorlib中。这是所有内置ontop .NET4与VS2010,所以没有单或其他怪异库的问题。上午我在想这?这是怎么回事?

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?

的问题是,你有你的版本不匹配。确保所有的组件都被编译为.NET 4。

The problem is that you have a mismatch in your versions. Make sure all your assemblies are compiled for .NET 4.