程序集加载失败,没有融合日志错误

Assembly fails to load, no fusion log error

我有一个非常简单的控制台应用程序,它只是试图从引用的程序集中打印出枚举的值。让我们称程序集为“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 说它引用了 mscorlibSystemSystem.Configuration.InstallSystem.DataSystem.Xml、和 Kernel32.dll。我还添加了所有列出的 .NET 程序集作为对控制台应用程序的引用。

我的控制台应用程序针对 x64 平台和 .NET 4.5.1,这与 VendorAssembly.DDK.dll 上的元数据完全匹配。

我需要做什么才能正确加载此程序集?

为什么 fuslogvw 不显示出了什么问题?

程序集加载失败是由 VendorAssembly.DDK.dllunmanaged (C++ DLL) 依赖项引起的,这些依赖项在 Visual Studio 的程序集资源管理器中不可见,是fuslogvw.exe 显示的 Fusion 日志中未提及,.NET 反射异常堆栈跟踪中未详细说明。

我使用 Dependency Walker 来识别和分析非托管依赖项。

另一个用于识别非托管依赖项缺失的有用工具是 Sysinternals Process Monitor (Procmon),它可以在进程加载失败时在运行时列出缺失的非托管依赖项的名称。