无法加载文件或程序集……但首先无法加载?

时间:2019-11-20 11:46:04

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

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

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

  • 无法加载文件或程序集'System.IO.Compression,版本= 4.2.0.0,文化=中性,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。

但是从全球范围来看,我不了解的事实是它可以工作一段时间(通常大约一两个小时),然后除非我重新启动服务,错误才会开始?

>

欢迎任何建议!

谢谢


编辑1:

我在“ Veeam Connector”项目中添加了更多日志和自定义异常,但这是一回事:最终错误仍然是有关System.IO.Compression丢失的,并且输入从未更改:

detailedlogswithsteps

stillsameerrorevenwithcustomexception

1 个答案:

答案 0 :(得分:0)

@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”即可!