What kind of problem can cause a TypeLoadException?

江枫思渺然 提交于 2019-12-01 01:52:16

Possible issues include:

  1. The assembly you reference is x64 only and your consumer is x86 or AnyCPU on a 32-Bit CLR
  2. Your consumer assembly was compiled against a different version of the referenced assembly

You can try to use FusLogVW to turn on assembly binding logging and check the logfile for more information about what failed.

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

TypeLoadException uses the HRESULT COR_E_TYPELOAD, that has the value 0x80131522.

For a list of initial property values for an instance of TypeLoadException, see the TypeLoadException constructors.

Source: MSDN

Just to add another answer to this:

we had a C++ client calling a .NET COM dll.

The developer of the .NET dll renamed the namespace enclosing the C# classes, and although the progid remained the same in both the class attribute and in the C++ calling code, the runtime failed to load the object resulting in this error.

I finally found a reason for this bug : apparently, in some cases referencing a .exe file does not work properly. Some methods and classes loads OK but some fails. In another project, referencing this .exe file cause no problem.

Switching to the .dll format solved all linking problems. I think this is a bug in the CLR.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!