我有一个非常小的控制台应用程序,它只是试图从引用的程序集中打印出枚举的值。让我们调用程序集“VendorAssembly.DDK.dll”,并说它定义“Vendor.Namespace”。这是我的匿名测试代码。 IntervalType只是一个枚举。
using Vendor.Namespace;
class Program
{
static void Main(string[] args)
{
try
{
IntervalType h = IntervalType.Hours;
Console.WriteLine($"{h}");
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
它汇编得很好。
但是当我尝试运行它时,会立即发生异常(在实际输入Main()方法之前),它说:
System.IO.FileNotFoundException was unhandled
Message: An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'VendorAssembly.DDK.dll' or one of its dependencies. The specified module could not be found.
即使我尝试多次运行此应用程序,fuslogvw.exe也不会列出任何绑定错误。将fuslogvw.exe设置为“将所有绑定到磁盘”并启用自定义日志路径后,搜索自定义融合日志文件夹会显示一个绑定事件,这显然是成功的吗?
*** Assembly Binder Log Entry (19/01/2018 @ 6:09:45 PM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\SVN\redacted\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = VendorAssembly.DDK, Version=6.77.6580.1, Culture=neutral, PublicKeyToken=9e16b9dd55e2cd53
(Fully-specified)
LOG: Appbase = file:///C:/SVN/redacted/ConsoleApplication1/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ConsoleApplication1.vshost.exe
Calling assembly : ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\SVN\redacted\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Publisher policy file is found at C:\WINDOWS\Microsoft.Net\assembly\GAC_64\policy.6.77.VendorAssembly.DDK\v4.0_6.77.6580.1__9e16b9dd55e2cd53\policy.6.77.VendorAssembly.DDK.config.
LOG: Publisher policy file redirect is found: 6.77.6580.1 redirected to 6.77.6580.1.
LOG: ProcessorArchitecture is locked to AMD64.
LOG: Post-policy reference: VendorAssembly.DDK, Version=6.77.6580.1, Culture=neutral, PublicKeyToken=9e16b9dd55e2cd53, processorArchitecture=AMD64
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\WINDOWS\Microsoft.Net\assembly\GAC_64\VendorAssembly.DDK\v4.0_6.77.6580.1__9e16b9dd55e2cd53\VendorAssembly.DDK.dll.
LOG: Assembly is loaded in default load context.
VendorAssembly.DDK.DLL是一个托管包装器,它调用非托管C ++代码。查看Visual Studio Assembly Explorer中的VendorAssembly.DDK.dll表示它引用了mscorlib
,System
,System.Configuration.Install
,System.Data
,System.Xml
和{{ 1}}。我已将所有列出的.NET程序集添加为Console应用程序的引用。
我的控制台应用程序面向x64平台和.NET 4.5.1,它与VendorAssembly.DDK.dll上的元数据完全匹配。
如何正确加载此程序集需要做什么?
为什么fuslogvw没有显示出错的地方?
答案 0 :(得分:1)
程序集加载失败是由{em>非托管(C ++ DLL)VendorAssembly.DDK.dll
依赖项引起的,这些依赖项在Visual Studio的Assembly Explorer中不可见,在Fusion日志中未提及由fuslogvw.exe显示,并且未在.NET反射异常堆栈跟踪中详细说明。
我使用Dependency Walker来识别和分析非托管依赖项。
另一个用于识别非托管依赖项缺失的有用工具是Sysinternals Process Monitor (Procmon),它可以在进程无法加载时列出运行时缺少的非托管依赖项的名称。