我创建了一个图表 C# 库(我们称之为 chartlibrary
),它本身依赖于多个第三方 dll 文件。
在另一个可执行项目(我们称之为 chartuser
)中,我引用了 chartlibrary
项目(这两个项目都位于 Visual Studio 中的同一个解决方案中)。
编译后可以看到chartlibrary
引用的所有第三方dll文件也包含在chartuser
的bin/Debug文件夹中。但是,我收到一个运行时错误,它基本上指出了 chartlibrary
中的某些引用无法解析的事实。然后我试图通过
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
非常神秘。
我做错了什么,即使所有的 dll 都在可执行项目的 bin/Debug 文件夹中,也找不到引用的 dll 并且无法解析程序集?
最佳答案
Fix: A fix for the third party library related to their obfuscation engine solved the issue.
.NET 依赖项:也许浏览一下这个旧答案:How do I determine the dependencies of a .NET application? - 并检查任何 list 文件?
调试:The Microsoft Assembly Binding Log Viewer可以告诉你运行时发生了什么。通过 Visual Studio 开发人员命令提示符
启动它(只需搜索“开发人员命令”,输入 “FUSLOGVW.exe”
并按 Enter
)。也可能略读一下:How the Runtime Locates Assemblies .
我不太熟悉它们的用途,但还有一些更进一步的工具(大多数都有超越依赖项的进一步用途):
应用启动 list :
- Desktop applicaton not opening after installation in client system
- Windows Application Startup Error Exception code: 0xe0434352
运行时:如果问题发生在另一台计算机上,则检查列表中最先出现的明显运行时:.Net
、.Net Core
, Java
, Silverlight
, Direct X
, VC++ Runtime
, MS-XML(旧版)
、Crystal Reports
、Microsoft Report Viewer
、SQL Server/Database Runtimes
等...加上任何涉及 COM 注册的内容,显然还有您引用的任何第三方框架组件(COM、COM Interop、GAC、程序集等)。
其他链接:
关于c# - VS C# 中的依赖 hell ,找不到依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57884104/