【问题标题】:Could not load file or assembly ... but not at first?无法加载文件或程序集......但不是一开始?
【发布时间】:2020-03-16 03:04:25
【问题描述】:

我有一个用于归档 Exchange 邮箱的 C#/.NET Windows 服务,我最近“打包”了 Veeam O365 Backup DLL,以便能够自动备份 Exchange Online 邮箱。

我会给你看一些日志,显示程序运行了一段时间没有问题,然后开始突然失败并出现错误:

  • "无法加载文件或程序集 'System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 或其依赖项之一。找到的程序集的清单定义与程序集不匹配参考。"

...直到服务重新启动:

(见Edit1,我的图片被覆盖了)

堆栈跟踪:

System.Management.Automation.CmdletInvocationException: Could not load file or assembly 'System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) ---> System.IO.FileLoadException: Could not load file or assembly 'System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at Veeam.Core.FileLoggerTransport.AutoArchive()
   at Veeam.Core.FileLoggerTransport.ArchiveAndDelete()
   at Veeam.Core.FileLoggerTransport.ControlLogSize()
   at Veeam.Core.FileLoggerTransport.WriteLine(UInt32 level, String message)
   at Veeam.Core.LoggerTransport.LogDefault(UInt32 level, String message, Object[] args)
   at Veeam.PowerShell.Core.BasePSCmdlet.BeginProcessing()
   at System.Management.Automation.Cmdlet.DoBeginProcessing()
   at System.Management.Automation.CommandProcessorBase.DoBegin()
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at VeeamArchiverConnector.VeeamArchiverConnector.ConnectToVeeamServer(String serverName, Int32 port)
   at REMOVED.DeprovisionObject.DeprovisionOnline(String deprovisioningOu) in C:\Users\REMOVED\Source\Repos\ExchangeProvisioning\Deprovisioning\DeprovisionObject.cs:line 442
   at REMOVED.DeprovisionObject.Start() in C:\Users\REMOVED\Source\Repos\ExchangeProvisioning\Deprovisioning\DeprovisionObject.cs:line 125 

该项目确实引用了 System.IO.Compression,但:

  • Nuget 包版本是“4.3.0”
  • 参考上的版本是“4.1.2.0”
  • 构建后的文件版本为“4.6.24704”

在我的 .csproj 文件中,我有这个:

<Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath>
      <Private>True</Private>
      <Private>True</Private>
</Reference>

我无权访问“Veeam.Core.*”的代码/项目,因为它们是 Veeam O365 备份安装程序随附的 Veeam DLL。

但在全球范围内我不明白的是,它工作了一段时间(通常大约一两个小时),然后除非我重新启动服务,否则错误就会开始? p>

欢迎任何建议!

谢谢


编辑1:

我在“Veeam 连接器”项目中添加了更多日志和自定义异常抛出,但它是同一件事:最终错误仍然是关于 System.IO.Compression 丢失,并且输入从未改变:

detailedlogswithsteps

stillsameerrorevenwithcustomexception

【问题讨论】:

  • 我看起来你输入错误。尝试使用以前有效的输入运行,以确保代码仍然运行。
  • 感谢您的回复,我会尝试添加更多有关输入的日志,但请注意,在我向您展示的整个执行过程中它们永远不会改变:一旦服务启动,它就会一直循环运行具有相同的输入参数(veeams 服务器和端口)。这是我的大问题。发生错误时,调用与 15 分钟前相比没有什么不同。
  • 不是解决方案,但这个blog 帮助我调试了与缺少程序集和无法加载文件/程序集相关的运行时问题。它可以帮助你
  • @Badri 谢谢,我一定会检查这个链接
  • 绑定重定向不会这样做,因为没有 4.3.0.0 版本。这很令人困惑,因为 4.3.0 包中包含 4.1.2.0 版本。看看stackoverflow.com/questions/55037565/…

标签: c# .net powershell .net-assembly veeam


【解决方案1】:

@howcheng 谢谢!这样就成功了,服务运行了多个小时,没有任何问题。

所以问题是这个绑定:

<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />

那是重定向到 4.2.0.0。我想它在我唯一的 .NETFramework 项目上很好,但正如你所提到的,.NETStandard System.IO.Compression 强制使用 4.1.2.0 版本,并且在安装时没有更新绑定 > 所以它现在正试图找到 4.2。 0.0,没有了,只有4.1.2.0。

将绑定更新为“newVersion=4.1.2.0”就可以了!

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。 netstandard2.0 库正在使用 System.IO.Compression,并从 .NET Fx 4.7.2 测试项目中使用。 Could not load file or assembly 'System.IO.Compression, Version=4.2.2.0, Culture=neutral' 尝试从netstandard2.0 代码。

    修复只是为了

    1. 参考 .NET Fx 4.7.2 测试项目中的 System.IO.Compression

    2. 从测试中调用这个方法,这样System.IO.Compression是从.NET Fx环境中解析出来的。

      private static void AvoidCannotLoadSystemIOCompressionException() {
       var justToAvoidStrangeException = ZipArchiveMode.Create;
      }
      

    奇怪,但它有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      相关资源
      最近更新 更多