Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

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

Closed
kichalla opened this issue Apr 7, 2017 · 9 comments

Comments

@kichalla
Copy link

kichalla commented Apr 7, 2017

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

@weshaggard
Copy link
Member

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

@kichalla
Copy link
Author

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 #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": {}
        }
      },

@weshaggard
Copy link
Member

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?

@kichalla
Copy link
Author

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

@weshaggard
Copy link
Member

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.

@ericstj
Copy link
Member

ericstj commented Apr 13, 2017

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.

@Eilon
Copy link
Member

Eilon commented Apr 13, 2017

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).

@PayscaleNateW
Copy link

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

@GSPP
Copy link

GSPP commented Oct 15, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants