What kind of problem can cause a TypeLoadException?

前端 未结 4 1449
礼貌的吻别
礼貌的吻别 2021-01-07 13:33

I have a big and bloated software and I want to add a new GUI element to it. The GUI element was written using XAML and WPF. I created the UI element in a separate assembly,

相关标签:
4条回答
  • 2021-01-07 13:59

    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

    0 讨论(0)
  • 2021-01-07 14:17

    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.

    0 讨论(0)
  • 2021-01-07 14:20

    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.

    0 讨论(0)
  • 2021-01-07 14:22

    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.

    0 讨论(0)
提交回复
热议问题