21

.NET Core 3.1 console app generates error during build -

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

But it works on .NET Core 3.0 version.

I'm using Microsoft.Orleans. This is csproj -

    <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Orleans.Core" Version="3.0.2" />
    <PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="3.0.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>
Silenus
  • 667
  • 1
  • 7
  • 16
  • Please, share your code and `csproj` file – Pavel Anikhouski Jan 06 '20 at 10:05
  • Please, add it to the question – Pavel Anikhouski Jan 06 '20 at 10:16
  • 2
    Exact same problem [is here](https://github.com/dotnet/orleans/issues/5245), you need the updated code generator. Assuming they have one, you might be stuck on 3.0 until they catch up. Just wait for the response on the github issue you added. – Hans Passant Jan 06 '20 at 14:45
  • 1
    Answers here may be useful to (if you are arriving from a 4.2.2. problem and not Core) https://stackoverflow.com/questions/42755274/visual-studio-2017-could-not-load-file-or-assembly-system-runtime-version-4 – d219 Aug 30 '20 at 17:15

5 Answers5

9

In my case Nischal Nigam's solution didn't worked out, so what I did, I updated the package Microsoft.NET.Sdk.Functions from version 1.0... to 3.0.11 and after that it started working just fine.

donatasj87
  • 760
  • 9
  • 23
9

Make sure you load your project properly (not just the folder which contains the project). In my case, instead of loading the .csproj file, I loaded just the folder which contains the whole project. What I did then, reloaded and clicked the .csproj file explicitly, then it came back to normal.

Alex
  • 601
  • 8
  • 22
8

I am using Microsoft Visual Studio - Version 16.4.5

Go to the following location and open the devenv.exe.config file in a text editor:

C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\16.0_1832c881\devenv.exe.config

Paste this binding in <configuration> -> <runtime> -> <assemblyBinding>

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

After this, save the file and restart Visual Studio.

2

ReubenBond helped me with solution. I used Microsoft.Orleans.CodeGenerator.MSBuild package instead of Microsoft.Orleans.OrleansCodeGenerator.Build.

Silenus
  • 667
  • 1
  • 7
  • 16
0
  1. Load your project by double clicking on the "NameOfYourFile.csproj"
  2. In the menu bar, click Project => properties of "NameOfYourFile. Choose "Application" and select a valid Framework Target (the newest in the list).
  3. Rebuil, it should work.
Pierre
  • 1