A .NET exception (TypeLoadException) occured in th

2019-08-31 17:41发布

问题:

I have a Visual studio project with lots of commercial DLL files that I use in my program. I have used many of these DLL files so far without any problem.

Yesterday I had to use a yet another DLL file. I linked the DLL file as a referense (as usual), I can see it is added to the project since code-completion works and I could build the project successfully.

But when I run this on the target PC, I get a TypeLoadException.

A .NET exception (TypeLoadException) occured in the module

I tried to catch and print the exact information in the exception but I did not help at all.

Below is the complete exception that I receive:

A .NET exception (TypeLoadException) occured in the module LightSwitch\nError message: Could not load type 'Backbone2.LightMode_Status_Ctr_1' from assembly 'Backbone2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.\nThrowing method: DiagModule.SetSwitch\n

(I can not perform any debugging and provide more info, since I build my project as dll which is then used on the target PC, and actually I can run the program on my PC since it is missing all the required hardware)

回答1:

Check whether the dll is built for the same architecture as your pc. I mean, if your pc is 64 bit, make sure that the dll is built corresponding to that and vice versa



回答2:

Thanks for all the replies, I managed to find the issue. The problem was that the project included a couple of library files (dll) with different versions in different folders. During runtime (still don´t know why) a dll file would be choose and since the file was different between different versions, some methods were missing. So updating the DLL files to the same version in all folders fixed the issue.



回答3:

Check that the DLL is in the right location (or in GAC) on the target PC.



回答4:

Launch FusLogVw.exe -- it is part of .Net SDK and could be launched from VS 2010 command prompt. Configure logging to record all failures. Reproduce problem, refresh view in FusLogVw.exe window. You should be able to find record that corresponds to your problem, it will tell you exactly what it is doing and you should be able to figure out how to correct the problem.



回答5:

Check if you are reference one version of the DLL and another one is loaded (from GAC) during runtime.



标签: c# exception dll