Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug "Could not load file or assembly" runtime errors?

I have a project that uses a Java library converted using IKVM. I added the created DLL plus all possible IKVM DLLs as references to my project, but when I run it, I get the following runtime error:

System.IO.FileNotFoundException : Could not load file or assembly 'core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

I'm not really sure how to debug this error. Is there a way to know exactly which type is missing? From the description I'd guess this is the generated DLL (from the Java lib) but I have properly added it as reference.

What else have I done wrong?

like image 344
Wookai Avatar asked Jan 05 '11 10:01

Wookai


People also ask

How do you fix Could not load file or assembly or one of its dependencies?

There are some workarounds for this issue: The dll file may not be in /bin folder. Just copy the dll file to /bin folder or set this preference Copy Local = True from Visual Studio. If the problem persists, check if the version of the assembly that is referenced is different than the version it is looking for.

Could not load file or assembly assembly load?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.

Could not load file or assembly Publickeytoken null or one of its dependencies?

This error usually means that the assembly was not found. Try verifying that the file exists in the directory where your application is running.

Could not load file or assembly Microsoft practices EnterpriseLibrary common?

This error means that ASP.NET was not able to find the EnterpriseLibrary dll. To fix it, try install Enterprise Library on the web server or upload the required dll into the bin folder.


2 Answers

You can use the Fusion Log Viewer to debug assembly loading problems in .NET apps.

Also, Process Monitor is very useful in identifying general file-load problems.

like image 87
Tim Barrass Avatar answered Sep 27 '22 20:09

Tim Barrass


Just chiming in that dependency walker and fusion log viewer dont work well for applications that have native and managed code together or doing dynamic loading of native code. Here is a good post explaining step by step how to solve missing (or invalid permission) assembly errors using process monitor that covers those scenarios:

Debug Could not load file or assembly or one of its dependencies error with Process Monitor

The post also includes a tool to automate some of this task as well

like image 24
devshorts Avatar answered Sep 27 '22 19:09

devshorts