【问题标题】:Assembly fails to load, no fusion log error程序集加载失败,没有融合日志错误
【发布时间】:2018-06-28 13:41:27
【问题描述】:

我有一个非常小的控制台应用程序,它只是尝试从引用的程序集中打印出枚举的值。我们将程序集称为“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 不显示出了什么问题?

【问题讨论】:

  • 处理器架构锁定为 AMD64。你的申请还可以吗?另外,我会检查一下 PublicKeyToken=9e16b9dd55e2cd53 在 csproj b packages.config 中是否相同,以防万一。
  • 我认为处理器架构锁定到 AMD64 应该没问题...我的应用程序专门针对 x64,而不是 AnyCPU,因此。我只需要 x64 版本,不需要 x86 版本。我会检查公钥令牌。
  • 哦,你提到了packages.config。这些程序集作为 MSI 的一部分安装在计算机上,不能通过 NuGet 获得。

标签: c# .net dll assembly-loading fuslogvw


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    相关资源
    最近更新 更多