Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Projects
None yet
6 participants
@kichalla
Copy link

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

This comment has been minimized.

Copy link
Member

commented Apr 10, 2017

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

@kichalla

This comment has been minimized.

Copy link
Author

commented Apr 10, 2017

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

This comment has been minimized.

Copy link
Member

commented Apr 10, 2017

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

This comment has been minimized.

Copy link
Author

commented Apr 10, 2017

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

@weshaggard

This comment has been minimized.

Copy link
Member

commented Apr 10, 2017

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

commented Apr 28, 2017

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

@GSPP

This comment has been minimized.

Copy link

commented Oct 15, 2018

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.

dotnet/corefx#32587
dotnet/corefx#32561
#481
#567
#558
#887
#891
dotnet/corefx#32610
dotnet/corefx#30642
dotnet/corefx#32757
#895
#877
#521
#295
#476
#184
#936
#941
dotnet/corefx#33148
NuGet/Home#7440
dotnet/corefx#31532
dotnet/corefx#22781
dotnet/corefx#23306
dotnet/corefx#29622
dotnet/corefx#9846
dotnet/corefx#17522
dotnet/corefx#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.