Mocha
Mocha

Reputation: 191

Cannot load file or assembly System.Runtime

I have two projects in one solution. One is a class library that has three nuget packages installed: HtmlAgilityPack, Microsoft.Syndication, and IrcDotNet. The other is the startup project, a console application project with only one Nuget Package installed, Microsoft.Syndication. This project also has a dependency on the class library. When I run the startup project, I get an exception with the following details.

System.IO.FileNotFoundException occurred HResult=0x80070002 Message=Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source= StackTrace: at AlexiConsole.Program.Main(String[] args) in c:\Users\myself\documents\visual studio 2017\Projects\Alexi\AlexiConsole\Program.cs:line 21

Inner Exception 1: 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 don't know why. I already have binding redirects in the app.config of both projects for redirecting versions 0.0.0.0-4.1.0.0 to 4.1.0.0.

Both project target .NET 4.7.

Upvotes: 4

Views: 23157

Answers (5)

Carlost
Carlost

Reputation: 865

For anyone in the future.

You can also try deleting your temporary ASP.NET Files, look for this folder:

C:\Windows\Microsoft.NET\Framework[yourversionNumber]\Temporary ASP.NET Files

Also, try this one

C:\Users[YourUser]\AppData\Local\Temp\Temporary ASP.NET Files

Upvotes: 1

skst
skst

Reputation: 627

In my case, my WPF executable started crashing when I made a Grpc call. It turns out the project's app.config file contained some assembly bindings left over from IDK what (VS 2019 16.3 update? NuGet update?). After I deleted them, it worked again.

Exception

System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Source=System.Memory StackTrace: at System.SpanHelpers.PerTypeValues'1.MeasureArrayAdjustment() at System.SpanHelpers.PerTypeValues'1..cctor()

Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.


App.config

Delete these bindings:

<dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> </dependentAssembly>

Upvotes: 1

Masoud Darvishian
Masoud Darvishian

Reputation: 3964

I had faced the same issue. Just follow these steps to solve your problem

  • Right Click on your solution and choose Manage NuGet Packages for Solution
  • In the Installed tab search System.Runtime
  • Now you can see in which projects you have installed the library
  • Select proper projects and downgrade System.Runtime to the previous version and upgrade it again
  • Clean & Rebuild your solution
  • Run project

It should works now.

Upvotes: 4

Rahul Shete
Rahul Shete

Reputation: 61

I have face same issue, My issue is

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.

To Solve this issue, Comment assembly <dependentAssembly></dependentAssembly> which Contain culture="neutral" in Web.config File and Rebuild Application. My application run properly and Problem Solve.

Upvotes: 6

Mocha
Mocha

Reputation: 191

I resolved the issue myself. I recreated both projects, targeting .NET 4.7, and the issue was resolved.

Maybe the problem was that I originally targeted an earlier version of .NET and then changed the version. But I am not sure.

Upvotes: 2

Related Questions