DLL Hell with .net core and .net (Azure WebJobs) - c#

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.

Related

Could not load file or assembly Microsoft.AspNetCore.Http.Abstractions, Version=5.0.0.0,

I have a console application on net 5.0.
I'm trying to load assembly at runtime:
Assembly loadedAssembly = Assembly.LoadFrom(assemblyPath);
var controllers = loadedAssembly.GetExportedTypes();
Method GetExportedTypes throws this exception
Could not load file or assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot
find the file specified.
I don't have such library in any of my project files. Assembly also has target framework 5.0
Can't find similar error by search in internet. What it can be?
Add
<FrameworkReference Include="Microsoft.AspNetCore.App" />
to the erroring projects csproj or vbproj file and the error will disappear.
Edit:
The error can occur with v6 DLLs as well:
Could not load file or assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=6.0.0.0
The solution is to remove the PackageReference and replace it with the FrameworkReference.

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 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

Exception thrown: 'System.IO.FileNotFoundException' in Prism.Wpf.dll

System.IO.FileNotFoundException: 'Could not load file or assembly
'System.Runtime, Version=4.0.20.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.'
I have reinstalled all of my packages and tried to solve this issue. I don't understand why it is doing this all of the sudden. Any help in this matter will be appreciated.
My Prism application and modules are targeting 4.6 .NET Framework, I also have a .NET Standard 1.3 PCL.
I tried reinstalling VS, reinstalling packages, changing my target framework.
Thank you.
What seemed to work is adding a reference to the System.Runtime library at:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Facades\System.Runtime.dll

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.

Categories