1
votes

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?

5
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
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
Ok, if it's not .net core, @Scircia solution should fix the issue. - Claudio Valerio

5 Answers

4
votes

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.

3
votes

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.

2
votes

This is quite an annoying issue. From what i noticed it's being cause by dependentAssembly once you install a new package or update it. Atleas that was 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 you 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 doens't work you could check this link out. Might be an option which will work for you.

1
votes

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.

0
votes

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.