3

我有一个非常小的控制台应用程序,它只是试图从引用的程序集中打印出枚举的值。我们将程序集称为“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 未处理 消息:mscorlib.dll 中发生“System.IO.FileNotFoundException”类型的未处理异常附加信息:无法加载文件或程序集“VendorAssembly.DDK.dll”或其依赖项之一。指定的模块无法找到。

即使我多次尝试运行此应用程序,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 程序集资源管理器中查看 VendorAssembly.DDK.dll 表示它引用了mscorlibSystemSystem.Configuration.InstallSystem.DataSystem.XmlKernel32.dll. 我还添加了所有列出的 .NET 程序集作为对控制台应用程序的引用。

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

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

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

4

1 回答 1

3

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

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

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

于 2018-01-22T02:26:12.590 回答