Matt
Matt

Reputation: 7254

Dependency hell in VS C#, cannot find dependencies

I created a chart C# library (let's call it chartlibrary) which itself has dependencies on multiple third-party dll files.

In another executable project (let's call it chartuser), I reference the chartlibrary project (both projects sit within the same solution in Visual Studio).

Upon compilation, I can see that all the third-party dll files that chartlibrary references are also contained in the bin/Debug folder of chartuser. However, I get a runtime error which basically points to the fact that some of the references in chartlibrary cannot be resolved. I then tried to get a better idea via

AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

and

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        var assemblyFileName = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
        var assemblyPathFileName = _currentPluginPath + @"\" + assemblyFileName;

        if (File.Exists(assemblyPathFileName))
        {
            return Assembly.Load(File.ReadAllBytes(assemblyPathFileName));
        }

        return null;
    }

Problem is that the RequestingAssembly is null and Name is very cryptic.

What am I doing wrong that the reference dlls cannot be found and assemblies cannot be resolved even though all the dlls are in the bin/Debug folder of the executable project?

Upvotes: 2

Views: 2334

Answers (1)

Stein Åsmul
Stein Åsmul

Reputation: 42136

Fix: A fix for the third party library related to their obfuscation engine solved the issue.


.NET Dependencies: Maybe skim this old answer: How do I determine the dependencies of a .NET application? - and go through any manifest files?

Debugging: The Microsoft Assembly Binding Log Viewer can show you what's going on at runtime. Launch it via a Developer Command Prompt for Visual Studio (just search for "developer command", type in "FUSLOGVW.exe" and press Enter). Also maybe have a skim: How the Runtime Locates Assemblies.

I am not familiar with their use that much, but there are some further tools (most have further uses beyond dependencies):

Application Launch Check-List:

Runtimes: If the issue happens on another computer, the obvious runtimes that are first on the check-list: .Net.Net CoreJavaSilverlightDirect XVC++ RuntimeMS-XML (legacy)Crystal Reports, Microsoft Report Viewer, SQL Server / Database Runtimes, etc... Plus anything involving COM-registration and obviously any third party framework components that you refer to (COM, COM Interop, GAC, Assemblies, etc...).


Other Links:

Upvotes: 1

Related Questions