VS C#中的依赖地狱,找不到依赖项 [英] Dependency hell in VS C#, cannot find dependencies
问题描述
我创建了一个图表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
为null,而 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 Dependencies: Maybe skim this old answer: How do I determine the dependencies of a .NET application? - and go through any manifest files?
调试 : "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.
应用启动清单 :
Application Launch Check-List:
运行时 :如果问题发生在另一台计算机上,则显而易见的运行时首先出现在检查列表中: .Net
, .Net Core
, Java
, Silverlight
, Direct X
, VC ++ Runtime
, MS-XML(旧版)
, Crystal Reports
, Microsoft Report Viewer
, SQL Server/数据库运行时
等...加上涉及COM注册的所有内容,以及您所引用的任何第三方框架组件(COM,COM Interop,GAC,Assemblies等).
Runtimes: If the issue happens on another computer, the obvious runtimes that are first on the check-list: .Net
, .Net Core
, Java
, Silverlight
, Direct X
, VC++ Runtime
, MS-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:
这篇关于VS C#中的依赖地狱,找不到依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!