title: Could not load file or assembly ... but not at first?
body: <p>I have a C# / .NET Windows service that is archiving Exchange mailboxes, and I recently &quot;packaged&quot; the Veeam O365 Backup DLLs to be able to backup Exchange Online mailboxes automatically.</p>
  <p>I 'll show you some piece of log showing that the program runs without issue for a while, then starts to fail out of nowhere with the error:</p>
  <ul>
  <li>&quot;<strong>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.</strong>&quot;</li>
  </ul>
  <p>... until the service is restarted:</p>
  <p>(see Edit1, my picture got overwritten)</p>
  <p>The stacktrace:</p>
  <pre class="lang-cs prettyprint-override"><code>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) ---&gt; 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 
  </code></pre>
  <p>The project does reference <strong>System.IO.Compression</strong>, although:</p>
  <ul>
  <li>The Nuget Package version is &quot;4.3.0&quot;</li>
  <li>The version on the reference is &quot;4.1.2.0&quot;</li>
  <li>The file version once built is &quot;4.6.24704&quot;</li>
  </ul>
  <p>In my .csproj file I have this:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Reference Include=&quot;System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL&quot;&gt;
        &lt;HintPath&gt;..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll&lt;/HintPath&gt;
        &lt;Private&gt;True&lt;/Private&gt;
        &lt;Private&gt;True&lt;/Private&gt;
  &lt;/Reference&gt;
  </code></pre>
  <p>I don't have access to the code / project of &quot;Veeam.Core.*&quot; as they are Veeam DLLs coming with the Veeam O365 backup installer.</p>
  <p>But globally what I don't understand, is the fact that it work for a while (<em>usually around an hour or two</em>), and then the error start unless I restart the service?</p>
  <p>Any advise is welcomed!</p>
  <p>Thanks</p>
  <hr />
  <h1>Edit 1 :</h1>
  <p>I added more logs and custom exception throw inside my &quot;Veeam Connector&quot; project, but it's the same thing: the final error is still about System.IO.Compression missing, and the inputs never changed:</p>
  <p><a href="https://i.stack.imgur.com/GtXSG.png" rel="nofollow noreferrer">detailedlogswithsteps</a></p>
  <p><a href="https://i.stack.imgur.com/1fBBR.jpg" rel="nofollow noreferrer">stillsameerrorevenwithcustomexception</a></p>