I have a C# / .NET Windows service that is archiving Exchange mailboxes, and I recently "packaged" the Veeam O365 Backup DLLs to be able to backup Exchange Online mailboxes automatically.
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:
"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."
... until the service is restarted:
(see Edit1, my picture got overwritten)
The stacktrace:
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
The project does reference System.IO.Compression, although:
The Nuget Package version is "4.3.0"
The version on the reference is "4.1.2.0"
The file version once built is "4.6.24704"
In my .csproj file I have this:
<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>
I don't have access to the code / project of "Veeam.Core.*" as they are Veeam DLLs coming with the Veeam O365 backup installer.
But globally what I don't understand, is the fact that it work for a while (usually around an hour or two), and then the error start unless I restart the service?
Any advise is welcomed!
Thanks
Edit 1 :
I added more logs and custom exception throw inside my "Veeam Connector" project, but it's the same thing: the final error is still about System.IO.Compression missing, and the inputs never changed:
detailedlogswithsteps
stillsameerrorevenwithcustomexception
#howcheng Thank you! That did the trick, service running for multiple hours with no issues.
So the issues was this binding:
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
That was redirecting to 4.2.0.0. I Suppose it was good on my only .NETFramework project, but as you mentioned, .NETStandard System.IO.Compression forces a version 4.1.2.0, and didn't update the binding when installed > so it was now trying to find 4.2.0.0, which was no more and it was only 4.1.2.0.
Updating the binding to "newVersion=4.1.2.0" did it!
I had the same problem. A netstandard2.0 library is using System.IO.Compression and is consumed from a .NET Fx 4.7.2 test project. The Could not load file or assembly 'System.IO.Compression, Version=4.2.2.0, Culture=neutral' exception happened when attempting to load System.IO.Compression from the netstandard2.0 code.
The fix was just to
reference System.IO.Compression from the .NET Fx 4.7.2 test project
call this method from the test, this way System.IO.Compression is resolved from a .NET Fx environement.
private static void AvoidCannotLoadSystemIOCompressionException() {
var justToAvoidStrangeException = ZipArchiveMode.Create;
}
Odd but it works
Related
My Web API is running on IIS 8.5 with .NET 4.6.1 installed. I added a new controller that connects to PostgreSQL database using Npgsql NuGet package.
Now I'm getting an exception on every request to that controller in production (on my local machine everything works as expected):
Could not load file or assembly 'System.Net.Sockets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Net.Sockets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Npgsql.NpgsqlConnector.d__154.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnector.d__152.MoveNext()
I changed Enable 32-Bit Applications to true in the application pool, but that did not solve the problem.
I'm using Visual Studio 2015.
UPDATE
If I add System.Net.Sockets but not version 4.2.0.0 I get an exception:
Could not load file or assembly 'System.Net.Sockets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
So, I have a WebJob project that needed updating. I was running into DLL issues which was solved by this post:
https://github.com/Azure/azure-webjobs-sdk/issues/1633
The last comment states:
I would recommend folks use the more recent versions:
Microsoft.Azure.WebJobs (2.2.0)
Microsoft.NET.Sdk.Functions (1.0.21)
Newtonsoft.Json (9.0.1)
So that is what I did and my WebJob compiles. Great.
Or so I thought. It turns out that my shared DLL uses the latest version of Newtonsoft's Json.Net (12.0.1) which is now throwing an error when I run my WebJob.
This is the error I am getting:
A ScriptHost error has occurred
[29/11/2018 10:17:08] Cormar.Extensions: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
[29/11/2018 10:17:08] Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
[29/11/2018 10:17:08] Cormar.Extensions: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
Does anyone know how I can get around this?
I managed to fix this.
I did what the post said and set my nuget package version to:
Microsoft.Azure.WebJobs (2.2.0)
Microsoft.NET.Sdk.Functions (1.0.21)
Newtonsoft.Json (9.0.1)
And then I just edited the WebJob .csproj file and changed the Nuget PackageReference to this:
<PackageReference Include="Newtonsoft.Json" Version="11.0.0.0" />
And it worked.
Is there a master list somewhere of all the odd NuGet version to Assembly version mappings? This is VERY confusing trying to upgrade old applications and debugging FileLoadException errors that ocur when Assembly Fusion runs. I have found a master matrix of all .NET Standard versions to .NET implementation versions, but nothing at the package-level.
Background for those unfamiliar:
Run Install-Package System.ComponentModel.Annotations -Version 4.5.0 or add this package to an empty .NET Standard or .NET Core project template in Visual Studio
Load your target framework's DLL and then grab the FullName:
$path = "C:\source\Infrastructure\SqlClone\Source\Company.Database.SqlCloneTask\packages\System.ComponentModel.Annotations.4.5.0\lib\net461\System.ComponentModel.Annotations.dll"
$assembly = [Reflection.Assembly]::ReflectionOnlyLoadFrom($path)
$assembly.FullName
This returns:
System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Then using the Version=4.2.10 and PublicKeyTooken=b03f5f7f11d50a3a to generate an runtime.assemblyBinding.dependentAssembly.bindingRedirect:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.2.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
The above steps are the only way I have found to reliably fix FileLoadException errors with bindingRedirect configurations, without using Google Search and finding a StackOverflow answer or GitHub issue :). Even right clicking Properties on the file and going to the Details tab shows:
File version: 4.6.26515.6
Product version: 4.6.26515.06 #BuiltBy: dlab-DDVSOWINAGE059 # Branch: release/2.1 #SrcCode: https://github.com/dotnet/corefx/tree/30ab651fcb4354552bd4891619a0bdd81e0ebdbf
Example errors (should help Google Search results):
System.IO.FileLoadException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 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.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
'Could not load file or assembly 'System.Configuration.ConfigurationManager,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one
of its dependencies. The system cannot find the file specified.'
Could not load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
in C# windows forms, I am creating a chat client to connect nodejs server (Socekt.io). I am using SocketIoClientDotNet.dll in C#. While in visual studio debug mode, all is well. But when I install the app through creating the installer of the app, it is giving the following error when I call the socket.Emit('func',data) function.
Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
This is the line where exception is occurring:
socket.Emit("msg", "text", txtMessage.Text, receiverId, senderId);
Make sure the Newtonsoft.Json.dll file is included in the installer.
You could also try (re)installing the SocketIoClientDotNet using NuGet.
PM> Install-Package SocketIoClientDotNet
I have a webproject I am trying to host, but when the server tries to compile it, I get the following error:
Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'Microsoft.CodeAnalysis, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' 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 'Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
--- End of inner exception stack trace --- at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args)
So the server has an older version of CodeAnalysis than my project. So lets try a binding redirect!
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.9.9.9" newVersion="1.0.0.0" />
</dependentAssembly>
Sadly, I still get the same error. What am I doing wrong?
I figured this out myself. To anyone reading this, the problem was that the Nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform (which also contains the CodeAnalysis package) was the wrong version. I created a new webproject, updated the offending Nuget package right away, and the problem was solved.
Other possible fix (at least for Visual Studio 2015):
Get the latest Visual Studio update.
You can check for updates by going to Tools/Extensions and Updates/Updates
Same as this Q/A: Visual Studio 2015: Quick Actions no longer working, error: Could not load file or assembly Microsoft.CodeAnalysis
I resolved this issue but ensuring that the version numbers of the assemblies in my web.config were correct.
Edit:
I hit this problem as well and some may wonder how the Web.Config can become incorrect. In my case I am using Web.Config Transforms so the Web.Config file gets overwritten:
Changing the version number in Web.Configs compiler (in the Web.Template.Config) to the number matches the NuGet version does solve the issue:
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0
I have had this problem today while doing an Umbraco v7.13.0 upgrade, simply updating the following package has fixed my problem, this is apparently a common problem with things like Umbraco upgrades.
Update-Package -Reinstall Microsoft.CodeAnalysis.CSharp
If none of mentioned options work, please go for this answer. Basically, you are registering that Microsoft.CodeAnalysis.dll to GAC
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependenc
Right click on your project >> Manage Nuget packages manager for solution >> Tap on Updates >> Update your 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform' >> and then run your project again.