【问题标题】:Strange C#.Net dependency between local dll and nuget lib本地 dll 和 nuget lib 之间奇怪的 C#.Net 依赖关系
【发布时间】:2018-07-06 15:53:01
【问题描述】:

我有一个 .Net 日志组件的项目。

当我在许多其他项目中使用它时,我过去决定将它推送到 nuget.org。在其他项目中,我确实引用了这个包。

到目前为止一切顺利。

现在我开始使用 Jenkins 设置部署服务器。

在 Jenkins 中,我有一个构建此日志组件并将工件 log.dll 复制到最终目的地的项目。

当与 nuget.org 包中的 log.dll 正常工作的组件使用 Jenkins 构建中的本地构建 log.dll 时。

我在事件日志中收到此错误:

Application: ServiceConsole.exe Framework Version: v4.0.30319 Description: 
The process was terminated due to an unhandled exception. 
Exception Info: 
System.IO.FileLoadException at ServiceConsole.MainForm..ctor() 
at ServiceConsole.Program.Main() 

还有一个

ServiceConsole.exe 
   2.10.0.0 
   5b3f4a6d 
   KERNELBASE.dll 
   10.0.14393.2312 
   5b1a1651 
   e0434352 
   0000000000033c58 
   480c 
   01d4153f46b746a1 
   C:\bin\ServiceConsole.exe 
   C:\Windows\System32\KERNELBASE.dll 
   05d03123-c336-4119-947f-7de71a75c0b5 

我确实比较了两个 dll(来自 nuget.org 并使用 jenkins (msbuild.exe) 本地构建)。

两个 dll 都有:

  • 等号
  • 大小相等
  • 编译发布
  • 构建相同的程序集版本
  • 产品版本相同

我想到的唯一区别是 Jenkins 中的 msbuild.exe 来自 VS2017 构建工具,而几个月前我在 nuget 上发布的 dll 是 VS2015。

有人知道这可能是什么吗?真的是编译器问题吗?

编辑很好奇并从 VS2015(版本 14)安装了 MSBuild.exe 并更改了 Jenkins 设置。使用此构建的本地构建也不起作用...

所以我认为我仍然存在的唯一区别是我在 nuget.org 上推送的前一个包是在我的开发机器上使用 VS2015 IDE 构建的。

编辑

甚至没有被触发的启动代码:

static class Program
    {
        private static readonly string _assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
      try
      {
        Console.WriteLine("starting app");
        using (var processLock = new ProcessLock(_assemblyName))
        {
          if (processLock.AlreadyExists)
            return;

          // The program operation must run inside the 'using' block.
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new MainForm());
        }
      }
      catch (Exception e)
      {
        Console.WriteLine(e);
        throw;
      }


    }
}

EDIT2

因此,似乎在最后一次推送 nuget 公钥令牌后更改签名密钥文件会更改并导致此错误。

start appSystem.IO.FileLoadException: Could not load file or assembly 'Common.Log, Version=2.10.0.0, Culture=neutral, PublicKeyToken=8a1542bdbac62407' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Common.Log, Version=2.10.0.0, Culture=neutral, PublicKeyToken=8a1542bdbac62407'
   at ServiceConsole.MainForm..ctor()
   at ServiceConsole.Program.Main()

=== Pre-bind state information ===
LOG: DisplayName = Common.Log, Version=2.10.0.0, Culture=neutral, PublicKeyToken=8a1542bdbac62407
 (Fully-specified)
LOG: Appbase = file:///C:/prog/bin/
LOG: Initial PrivatePath = NULL
Calling assembly : ServiceConsole, Version=2.10.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Common.Log, Version=2.10.0.0, Culture=neutral, PublicKeyToken=8a1542bdbac62407
LOG: Attempting download of new URL file:///C:/prog/bin/Common.Log.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

正在寻找确认。 因此,修复该问题的下一步是将新版本发布到 nuget 并使用它,但必须提高版本号。对吗?

【问题讨论】:

  • 从崩溃异常中了解完整的异常消息和堆栈跟踪非常有用,而不仅仅是它的类型。能否提供一些日志或相关信息?
  • 事件日志中没有堆栈跟踪,我的程序没有抛出异常,不知道为什么。我仍然试图找出发生了什么......
  • 我尝试从 VS IDE 重现此问题,但在 VS IDE 2017 的 Debug 中启动项目我没有收到任何错误...
  • 没有其他线索让猜测成为找到错误的唯一机会。至少,尝试在Main 中添加一个错误处理,将Exception.ToString() 写入文件并重新抛出,这将在纯文本文件中提供消息,并且只需更改几行。
  • 我确实添加了这个,但甚至没有被解雇。所以 IOLoadException 可能不在我的代码中,它是在加载 dll 引用时......

标签: c# jenkins nuget


【解决方案1】:

如果程序集在二进制比较中是相同的,并且一个加载但另一个不加载,则可能是一个安全问题。

.Net 跟踪程序集的来源,并对源自 Internet 的程序集应用不同的安全策略,例如防止您意外运行恶意代码。

如果从不同的地方复制两个相同的程序集,.Net 加载程序可能会以不同的方式处理它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    相关资源
    最近更新 更多