VS C# 中的依赖地狱,找不到依赖 [英] Dependency hell in VS C#, cannot find dependencies

查看:70
本文介绍了VS C# 中的依赖地狱,找不到依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个图表 C# 库(我们称之为 chartlibrary),它本身依赖于多个第三方 dll 文件.

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

在另一个可执行项目(我们称之为 chartuser)中,我引用了 chartlibrary 项目(两个项目位于 Visual Studio 中的同一个解决方案中).

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

编译后,可以看到chartlibrary引用的所有第三方dll文件也都包含在chartuser的bin/Debug文件夹中.但是,我收到一个运行时错误,这基本上表明 chartlibrary 中的某些引用无法解析.然后我试图通过

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;

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;
    }

问题是RequestingAssembly 为空,Name 非常神秘.

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

即使所有 dll 都在可执行项目的 bin/Debug 文件夹中,但找不到引用 dll 并且无法解析程序集,我做错了什么?

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?

推荐答案

修复:针对与混淆引擎相关的第三方库的修复解决了该问题.

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

<小时>

.NET 依赖项:也许略过这个旧答案:如何确定 .NET 应用程序的依赖项? - 并检查任何清单文件?


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

调试:Microsoft 程序集绑定日志查看器 可以显示运行时发生的情况.通过 Visual Studio 的开发人员命令提示符 启动它(只需搜索开发人员命令",输入 FUSLOGVW.exe" 并按 Enter).也可以略读一下:如何运行时定位程序集.

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.

应用启动清单:

运行时:如果问题发生在另一台计算机上,则首先出现在清单上的明显运行时:.Net.Net CoreJavaSilverlightDirect XVC++ RuntimeMS-XML (legacy)Crystal ReportsMicrosoft Report ViewerSQL Server/Database Runtimes 等...加上任何涉及 COM 注册的内容,以及您所指的任何第三方框架组件(COM、COM 互操作、GAC、程序集等).

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

其他链接:

这篇关于VS C# 中的依赖地狱,找不到依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆