yu yang Jian
yu yang Jian

Reputation: 7181

Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

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?

Upvotes: 12

Views: 107049

Answers (12)

blake
blake

Reputation: 601

For me this error appeared when using a csproj with invalid configuration, in particular the following:

    <ItemGroup>
        <Content Include="StaticAssets\**\*">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </ItemGroup>

Corrected to:

    <ItemGroup>
        <Content Include="StaticAssets\**\*">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

Upvotes: 0

Nick Chan Abdullah
Nick Chan Abdullah

Reputation: 385

none of the solutions above worked for my case. I got that error when running in debug mode. I switched to release, click run and stop. then switched back to debug, then it works.

Upvotes: 0

Eldar Scott
Eldar Scott

Reputation: 139

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

Upvotes: 0

B.samu
B.samu

Reputation: 41

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.

Upvotes: 4

Liviu Florin
Liviu Florin

Reputation: 21

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

Upvotes: 2

Lee
Lee

Reputation: 11

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.

Upvotes: 0

Scircia
Scircia

Reputation: 459

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.

Upvotes: 6

Nir
Nir

Reputation: 2082

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.

Upvotes: 0

Jason Alls
Jason Alls

Reputation: 209

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.

Upvotes: 2

Jean Gregory
Jean Gregory

Reputation: 398

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.

Upvotes: 16

Oushima
Oushima

Reputation: 279

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.

Upvotes: 20

yu yang Jian
yu yang Jian

Reputation: 7181

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.

Upvotes: 1

Related Questions