Dependency hell in VS C#, cannot find dependencies

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 00:49:53

问题


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?


回答1:


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):

  • ILSpy - I believe it is open source.
  • AsmSpy - never tried it.
  • NDepend - commercial.

Application Launch Check-List:

  • Desktop applicaton not opening after installation in client system
  • Windows Application Startup Error Exception code: 0xe0434352

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:

  • Which winform project files should be packed up into the installer


来源:https://stackoverflow.com/questions/57884104/dependency-hell-in-vs-c-cannot-find-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!