Standard: Running an application targeted for net461: Could not load file or assembly 'System.Runtime, Version=4.1.0.0'

Created on 7 Apr 2017  路  9Comments  路  Source: dotnet/standard

I am trying to run the MusicStore app on net461 and I am hitting the following error:

C:\github\musicstore\samples\MusicStore [dev +0 ~6 -0]> C:\github\musicstore\samples\MusicStore\bin\Debug\net461\MusicStore.exe

Unhandled Exception: System.IO.FileNotFoundException: 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. ---> System.IO.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.
   --- End of inner exception stack trace ---
   at MusicStore.Program.Main(String[] args)

My machine has .NET Framework 4.7 installed

cc @pranavkm

Most helpful comment

Do you have a package reference to NETStandard.Library package in your net461 project?

All 9 comments

Do you have a package reference to NETStandard.Library package in your net461 project?

No, I didn't have it earlier but added it now and was able to proceed further. I am now hitting an issue with System.Runtime.InteropServices.RuntimeInformation package. This is related to the issue https://github.com/dotnet/standard/issues/291. As mentioned in that issue, I am referencing to the latest package but the generated binding redirects do not point to the latest package's binary. For example, MusicStore depends on Hosting package which references a version of the package having 4.0.1 assembly version and the latest version of the package has a 4.0.2 assembly version and was expecting the binding redirect to point to 4.0.2 but instead it still points to 4.0.1.

Error

C:\github\musicstore\samples\MusicStore [kichalla/net461 鈮> C:\github\musicstore\samples\MusicStore\bin\Debug\net461\MusicStore.exe

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at MusicStore.Program.Main(String[] args)

You can find the diagnostic msbuild log file here: \\KICHALLAMAIN\MusicStore_OnNET461

packagereference

<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.4.0-*" />
<PackageReference Include="NETStandard.Library" Version="2.0.0-*" />

generated binding redirects

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>

assets.json

      "System.Runtime.InteropServices.RuntimeInformation/4.4.0-preview1-25210-01": {
        "type": "package",
        "frameworkAssemblies": [
          "mscorlib"
        ],
        "compile": {
          "ref/netstandard1.1/System.Runtime.InteropServices.RuntimeInformation.dll": {}
        },
        "runtime": {
          "runtimes/win/lib/net45/System.Runtime.InteropServices.RuntimeInformation.dll": {}
        }
      },

It looks like your log file got cut off right in the middle of the ResolveAssemblyReferences target which generates the binding redirects so I wasn't able to see if the resolution looks correct. Can you please update the log file to included the full one?

I put a new file msbuild_new.log. Could you try again?

Looks like we have a bug in the latest version of this package. The workaround however shouldn't really be needed any longer. Can you instead reference the "4.3.0" version of the RuntimeInformation package instead, assuming it is still needed.

Now we have a desktop-specific NETStandard support package (NETStandard.Library.NETFramework) which should be used instead of NETStandard.Library. With this package no additional reference is required for System.Runtime.InteropServices.RuntimeInformation. This should be available after the next successful corefx build on the dotnet-core myget feed.

I'm a bit fuzzy on some of this stuff, but are there cases (maybe System.Memory? Or the package mentioned earlier in this thread?) where a library/app, in addition to referencing the NuGet package it wants, must also reference an additional library that brings some additional implementation/references?

In other words, is the following statement true?

  • Whatever functionality an app/library wants to use, it can bring in some particular NuGet package, and that NuGet package will bring in all required dependencies (excluding actual OS dependencies and things that must be "installed" on the machine).

Installing NetStandardLibrary in my nunit 2.6.4 / .net framework 4.6.2 (not .netcore) unit tests project fixed my System.Runtime filenotfoundexception.

I'm tracking related issues and information in a list. They are related to System.Net.Http, System.Runtime, System.IO, System.ValueTuple, System.Buffers and others.

https://github.com/dotnet/corefx/issues/32587
https://github.com/dotnet/corefx/issues/32561
https://github.com/dotnet/standard/issues/481
https://github.com/dotnet/standard/issues/567
https://github.com/dotnet/standard/issues/558
https://github.com/dotnet/standard/issues/887
https://github.com/dotnet/standard/issues/891
https://github.com/dotnet/corefx/issues/32610
https://github.com/dotnet/corefx/issues/30642
https://github.com/dotnet/corefx/issues/32757
https://github.com/dotnet/standard/issues/895
https://github.com/dotnet/standard/issues/877
https://github.com/dotnet/standard/issues/521
https://github.com/dotnet/standard/issues/295
https://github.com/dotnet/standard/issues/476
https://github.com/dotnet/standard/issues/184
https://github.com/dotnet/standard/issues/936
https://github.com/dotnet/standard/issues/941
https://github.com/dotnet/corefx/issues/33148
https://github.com/NuGet/Home/issues/7440
https://github.com/dotnet/corefx/issues/31532
https://github.com/dotnet/corefx/issues/22781
https://github.com/dotnet/corefx/issues/23306
https://github.com/dotnet/corefx/issues/29622
https://github.com/dotnet/corefx/issues/9846
https://github.com/dotnet/corefx/issues/17522
https://github.com/dotnet/corefx/issues/25773

All of these have the same very few underlying issues.

.NET 4.7.2 helps with some but not all of these. You can look at my comments on some of these issues for some ideas on how to work around those problems. I also have a central list of ideas to try.

Was this page helpful?
0 / 5 - 0 ratings