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

36,288

Solution 1

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.

Solution 2

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

Solution 3

You can diagnose that by using Fusion Log Viewer (available in the Microsoft SDK). Launch it in Administrator and activate the log in the Settings.

It will log all the informations regarding your references loading (and all their references). It will explicitly tell you which reference is missing and where it has searched for it.

MSDN on Fusion Log Viewer

Solution 4

There is a program called Dependency Walker which allows you to see the dependencies of a given PE file (dll, exe, ocx...).

This error is really annoying, very difficult to debug. You have to make sure that your dll is present as well as ANY dependency this dll has. This keypoint is usually where the headache kicks in.

Share:
36,288
Wookai
Author by

Wookai

Swiss geek, interested in data mining and machine learning. #SOreadytohelp

Updated on July 23, 2022

Comments

  • Wookai
    Wookai almost 2 years

    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?