7

I got the project from colleague and got this error when building project:

Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I guess this dll is in .NET Framework Dll Folder: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework, but after searching, I find many dll of other version, but I didn't find any System.Runtime.dll is 4.2.1.0.

Here's another similar question but no answer to it.

Is System.Runtime.dll 4.2.1.0 really exists in .NET Framework?

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80
  • 1
    Is it .net core application? Are you sure you have required SDK / Runtime installed (ask your colleague)? It could be that some of your application referenced libraries statically references that particular version of Syste.Runtime.dll, but it is unusual. More info about the project would be needed. Maybe include csproj file in your question :) – Claudio Valerio Feb 28 '20 at 11:28
  • Yes there's another dll that use `4.2.1.0`. I think it's not .net core appplication. It's `Web Site project ` so it didn't have csproj file. I have asked my colleague, but he is also new to that project so he doesn't know solutio too, so I try to ask if there's a general way to find this version of dll. – yu yang Jian Feb 28 '20 at 11:39
  • 1
    Ok, if it's not .net core, @Scircia solution should fix the issue. – Claudio Valerio Feb 28 '20 at 12:15

10 Answers10

18

I know this is an old post, but I think it's useful to share my solution with others that encounter this exact problem.

  1. I created a new Console App via the terminal: dotnet new console
  2. I opened the folder of the Console App in Visual Studio 2019.
  3. I tried to run the code using ctrl + f5

That's when I encountered: Could not load file or assembly 'System.Runtime, Version=5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

To solve it, instead of opening the Console App folder in Visual Studio 2019, I had to open the file inside of it that ended with .csproj and then doing ctrl + f5. After that it ran smoothly. Hope this will help someone else. Been troubleshooting for a long time to find the solution.

TL;DR: open the .csproj file in Visual Studio 2019 instead of the project folder that it resides in.

Oushima
  • 250
  • 3
  • 7
13

This happens when you open the folder instead of the solution file. Simply ensure that you load the solution file and not the directory of your project.

Jean Gregory
  • 368
  • 5
  • 11
  • Nice answer! If you clone an empty repository and then create a project and solution, you won't be able to run it without closing the folder and opening the solution itself. – Chad Hedgcock Apr 11 '22 at 16:20
  • Perfect solution. If you have already opened the folder, double click on the solution file and it will open the project in the correct way. – TheTechGuy May 12 '23 at 02:51
3

This is quite an annoying issue. From what I noticed, it's being caused by dependentAssembly once you install a new package or update it. At least that was the root cause for me.

Try checking the dependentAssembly newVersion inside your Web.config. If I'm correct, you should have something like:

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

Make sure that your Web.config dependentAssembly matches the version defined inside the Web.Base.config (or the version inside the Nuget Package Manager). If not, change the newVersion= to the version you have installed in your Nuget Package Manager.

If that doesn't work, you could check this link out. Might be an option which will work for you.

Fab
  • 14,327
  • 5
  • 49
  • 68
Scircia
  • 419
  • 3
  • 10
  • 1
    Your answer inspire me and the problem is solved. Thank you very much! I'll post in my case what I try to solve the problem. – yu yang Jian Feb 28 '20 at 13:55
  • 2
    For my case, I actually had to REMOVE the `System.Runtime` and `System.Net.Http` bindings after changing targeting framework from 4.7 to 4.7.2 ‍♂️ – kamranicus Feb 24 '21 at 14:52
2

I had this problem today for System.Runtime 4.2.2.0. It happened when opening the folder for a solution in Visual Studio instead of opening the solution file instead. Closing Visual Studio 2019 down and clicking on the solution file to open it fixed my issue.

Jason Alls
  • 199
  • 1
  • 7
2

I know this is an old post but I think someone will need this answer.

To Solve this issue:

  1. Go to your project folder.
  2. Delete the bin file inside your project folder.
  3. Remove all added references.
  4. Load your project references again then run your software.

it will run without any problem.

B.samu
  • 21
  • 4
1

To solve the problem, I originally guess System.Runtime.dll should be in .NET Framework Dll Folder, because in Nuget Page of this dll, the version history doesn't contains 4.2.1.0, but after reading @Scircia answer, I try to add the latest Nuget System.Runtime.dll to the project by Right Click On Project > Property Page > References > Add. the Nuget version of the dll is 4.3.1, but its dll version is 4.6.27406.3.

After Adding, a new error show:

Assembly 'XXXX(It's secret), Version=x.x.x.x, Culture=neutral, PublicKeyToken=xx' uses 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

But the dll I add is 4.6.27406.3, why got this 4.0.0.0 error? After some try, I finally find the main cause is, in the project many component use .NET Framework 3.5 so it should be run at 3.5, but when I Right Click On Project > Property Page > Build > Target Framework, it shows currently use 4.0.

So I follow these step to change the Target Framework from 4.0 to 3.5 Click OK, then again from 3.5 to 4.0, then the error is solved. That is, through 4.0 > 3.5 > 4.0, the web.config is auto modifed and seems some dll that need 3.5 is removed, become a real 4.0, and in Framework 4.0 the System.Runtime.dll works good.

Since it says need 4.2.1.0, but I add 4.6.27406.3 works, so I suppose that use a higer version than 4.2.1.0 is allowed, not need to use exactly 4.2.1.0.

But another point is, since the project need to run at 3.5 to make the Web UI package works, after changing to 4.0, some of the UI control lost function.

So I conclude that the XXXX(It's secret).dll should not be use in the .NET Framework 3.5 project.

Besides I use Resharper to see the XXXX.dll shows that it's .NETCoreApp.

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80
1

I hade the same problem and I deleted Bin folder and Obj and the problem was solved.

  • This was what finally worked for me. Cleaning the solution, reinstalling all the Nuget packages, changing target versions, trying to manually install in GAC - nothing worked. After at least 7 hours of beating my head against the wall, deleting the Bin and Obj folders fixed the problem. In my case, it didn't fail when running under VisualStudio 2022, but when I deployed the executable, it failed on System.Reflection.TypeExtensions - saying it needed 4.1.0.0. – Kim Crosser Jul 05 '23 at 00:27
0

My quick solutions was deleting the [application name].config file to make it ran.

It might be good enough if you only need to make the program run.

Nir
  • 1,836
  • 23
  • 26
0

VS 17.5 contained a bug that required me to roll back to VS 17.4.5. This is when the error was introduced.

I resolved the error by using NuGet to install the previous version of System.Runtime then used NuGet to update to the current version.

Lee
  • 13
  • 1
  • 3
0

Try to do the following: find out your .NET version for the app and install the appropriate SDK.

Eldar Scott
  • 130
  • 1
  • 3