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
Related
I am getting a weird issue in the DotNet Framework 4.7.2 WebApi.
Error:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Collections, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source=Microsoft.Web.Administration
Recently, I had upgraded my webapi from 4.6 to 4.7.2 dotnet framework. The older version is working fine. I am getting this error on 4.7.2.
I noticed that when I run my Webapi on 4.6 version, I can see the following DLLs in the bin folder. However, when I run the same WebAPI on 4.7.2 version, I can not see DLLs in the bin folder.
System.Collections
System.Collections.NonGeneric
System.Collections.Specialized
System.Collections.Concurrent
I also got the same post on StackOverflow but there is no answer.
URL: Could not load file or assembly 'System.Collections, Version=4.0.0.0
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'
Full error message:
error CS0234: The type or namespace name 'GTK' does not exist in the namespace 'Xamarin.Forms.Platform' (are you missing an assembly reference?)
This occurs in Program.cs on this line:
using Xamarin.Forms.Platform.GTK;
The reason I had to change the .NET framework version is because I was trying to run the app on Linux, and Mono for Linux doesn't seem to support .NET Framework v4.7.2, so I changed it to 4.6.1 (the minimum required for Xamarin).
The weird thing is, if I open the file in question, Visual Studio says there are no errors, but the error still pops up in the output window when I actually try to build the project...
edit: there are some warnings above the error in the output window, here is the first one:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3274: The primary reference "Xamarin.Forms.Platform.GTK, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.7" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6.1".
This looks like I need to update my nuget packages, so I reinstalled the two Xamarin packages (Xamarin.Forms and Xamarin.Forms.Platform.GTK), and... same warning! Why can't nuget get the version of the package that is compatible with the version of .NET that I'm using?
edit: the reason I tried to change the .NET framework version is because I get this error running the Xamarin app on Linux:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
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.
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.