Datastax C# Driver .Build() Throws System.IO.FileLoadException - c#

looks like I have a binding redirects issue that I don't know how to solve.
When .Build() is called, I get the following exception:
[2020-10-09 14:09:28.806] [ :001] [ERROR] [DatabaseClient ] Failed to connect to Cassandra Database...
System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Dataflow, Version=4.6.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)
File name: 'System.Threading.Tasks.Dataflow, Version=4.6.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Cassandra.ProtocolEvents.ProtocolEventDebouncer..ctor(ITimerFactory timerFactory, TimeSpan delay, TimeSpan maxDelay)
at Cassandra.Cluster..ctor(IEnumerable`1 contactPoints, Configuration configuration)
at Cassandra.Cluster.BuildFrom(IInitializer initializer, IReadOnlyList`1 nonIpEndPointContactPoints, Configuration config)
at OpportunityRecorder.DatabaseClient.<ConnectToCassandraAsync>d__12.MoveNext() in C:\Gitlab-Runner\builds\4Gddire9\0\dev\V\OpportunityRecorder\OpportunityRecorder\DatabaseClient.cs:line 46
I have another project in this solution that references System.Threading.Tasks.Dataflow, Version=4.11.1.0.
This error doesn't happen locally, but happens when I deploy my application.
How can I fix this?

Can you try installing System.Threading.Tasks.Dataflow, Version=4.11.1.0 in the project that uses the DataStax driver?

Looks like there were two assemblies being references by the same set of projects, but with different versions. What I did was add both <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> and <PreserveCompilationContext>true</PreserveCompilationContext> to my .csproj file for my StartUp (main) project. This generated a binding reference in my App.config that would point all earlier versions of the assembly to a single version amongst all projects.

Related

Topshelf.HostFactory: Autofac missing assembly

I have problem with loading Autofac assembly on runtime in NET Core 3.1. In my project I have never use version 4.9.4, I have referenced only 6.3.0 version.
On starting application I get error
Topshelf.HostFactory Error: 0 : An exception occurred creating the
host, System.IO.FileLoadException: Could not load file or assembly
'Autofac, Version=4.9.4.0, Culture=neutral,
PublicKeyToken=17863af14b0044da' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
File name: 'Autofac, Version=4.9.4.0, Culture=neutral,
PublicKeyToken=17863af14b0044da'
My question is how to determine which assembly try to call Autofac in version 4.9.4?
How can I improve my logs to get such information?
Problem occurs on PROD env so we cannot use WinDbg or Fuslogvw.

Multiple Microsoft.Owin Versions with Nuget package

I am in front of a feature freeze in less than a week and I am looking for a way to upgrade Microsoft.Owin in one project only and keep referencing the old versions in other projects.
The goal under the hood is to use Microsoft.Owin.Security.OpenIdConnect with the version 4.1.0 providing me the support of AuthorizationCode flow.
My project is a C#, .NET web server using Owin.
PS : I am asking for a solution that doesn't modify the other project's *.csproj or *.config
And when I build and launch it, I got this error in the event viewer because there is a binding redirect on other projects that reference the version 3.1.0
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Owin.Hosting, Version=3.0.1.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)
File name: 'Microsoft.Owin.Hosting, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Could not load file or assembly ... but not at first?

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

Could not load file or assembly Newtonsoft.json Version 6.0.0.0

I am trying to update the NewtonSoft to it's latest addition 11.0.1 but when I updated the Dll using NuGet Manager then it started givng me this Error I even Deleted files from all the Temp folders that could be there for the ASP.NEt FrameWork but it seems not to be going away.
Error:
Reference.svcmap: Could not load file or assembly 'Newtonsoft.Json, Version=6.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)
What else can I try doing here?
Rebuilding the solution usually fixes this error for me

C# Error after installation. Could not load file or assembly 'Newtonsoft.Json

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

Categories