Multiple Microsoft.Owin Versions with Nuget package - c#

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'

Related

Nuget dll hell : How to solve "Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.5.4.0"

I have a test project that references a dll project; this dll project references itself Azure Nugets, especially Azure.Storage.Blobs (v12.9.1)
One of my tests fails when reaching this instruction :
var blobServiceClient = new BlobServiceClient(connectionString);
Exception is :
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.5.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=Azure.Storage.Blobs
StackTrace:
at Azure.Storage.Blobs.BlobServiceClient..ctor(String connectionString, BlobClientOptions options)
at Azure.Storage.Blobs.BlobServiceClient..ctor(String connectionString)
(…)
Inner Exception 1:
FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I would like to understand and solve this exception.
Notes :
UnitTest Project is using .Net Framework 4.7.2
Referenced project is using .Net standard 2.0, and references itself other projects.
System.Threading.Tasks.Extensions is neither referenced explicitly by my test project, nor by referenced dll.
What I already investigated :
Add bindingredirect in Test Project App.Config :
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.4.0" newVersion="4.5.4.0" />
</dependentAssembly>
Note : For the next steps of my investigation, I kept this binding redirect
Check that System.Threading.Tasks.Extensions.dll is present in test project bin/debug folder => It is the case, this dll is present. Note : I don't know how to detrmine its nuget version (details in windows explorer only gives dll version)
Adding a reference to nuget System.Threading.Tasks.Extensions v4.5.4.0 (latest version) to unit test project
Adding a reference to nuget System.Threading.Tasks.Extensions v4.5.4.0 (latest version) to referenced project
Thanks for help.
Since this solves your issue, I made a summary and hope this could also benefit other forum members who meet the similar/same issue.
For element, consider using assembly version, instead of NuGet package version. See here for details.
For System.Threading.Task.Extensions NuGet package, currently, 4.5.4 is the newest NuGet package version and 4.2.0.1 is the newest assembly version, so try to use 4.2.0.1.

DLL Hell with .net core and .net (Azure WebJobs)

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.

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

Why I can not use System.Net.Http package in a solution with System.Net.Http reference?

Using VS2017, I've created a ClassLibrary (.NET Framework 4.6.2) in an empty solution. Then I've installed System.Net.Http 4.3.2 package there and used HttpClient class in a Class1 constructor.
Then I've created a ConsoleApp (.NET Framework 4.6.2), referenced ClassLibrary and instantiated Class1 in the Main method.
Now running ConsoleApp causes runtime exception:
Unhandled Exception: System.IO.FileNotFoundException: Could not load
file or assembly 'System.Net.Http, Version=4.1.1.1, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified. at
ClassLibrary1.Class1..ctor() at ConsoleApp1.Program.Main(String[]
args) in [...]
In detailed build log I see this message:
2> There was a conflict between "System.Net.Http, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and
"System.Net.Http, Version=4.1.1.1, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a".
2> "System.Net.Http, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and
"System.Net.Http, Version=4.1.1.1, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" was not.
Let's suppose I can not remove reference to System.Net.Http from ConsoleApp, because I have this situation in a real project structure.
Playing with Specific Version parameter of System.Net.Http
reference did not help.
Specifying <bindingRedirect oldVersion="0.0.0.0-4.1.1.1"
newVersion="4.1.1.1" /> did not help
I've googled it and it is a popular problem, but I didn't find a clear explanation of what actually happens and how to fix such cases in general.
Could not load file or assembly System.Net.Http version 4.1.1.0
Could not load file or assembly 'System.Net.Http' or one of its dependencies
About conflicts:
What does .NET mean by 'primary' when choosing between conflict dll reference?
Found conflicts between different versions of the same dependent assembly that could not be resolved error
I wonder why you are choosing to use the NuGet package instead of using the Reference Manager to load in the appropriate assembly. By default in a lot of project templates VS includes System.Net.Http. If it is the case that you used the NuGet package explorer to install the assembly, then one of the two options should help out:
Remove the NuGet package and use the assigned version from the Reference Manager (look under Assemblies / Framework) though I am betting this is already selected.
In the Reference Manager un-select the assigned version of System.Net.Http and use the one that you installed with NuGet.
Personally I think option 1 is better unless you absolutely need something specific found only in the NuGet latest version.
The best and easiest way to fix this issue, is with a binding redirect, as said. But the versioning looks off.
Simply specify the oldVersion as 0.0.0.0-5.0.0.0, and newVersion as 4.1.1.0
Where 4.1.1.0 is your version, for example.

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