Install-Package : Failed to add reference to 'System.Runtime'

35,979

Solution 1

I had the same problem.

Found the solution here: https://github.com/aspnet/WebHooks/issues/18

To fix it, I added <Reference Include="System.Runtime"/> to the .csproj
file for the project, rebuilt it and it worked.

Solution 2

Please make sure that it is in the Global Assembly Cache.

That is an excessively unhelpful error message. It not only doesn't describe the real problem, it also leads you drastically astray to find a workaround. An assembly reference for a .NET Framework assembly must never come from the GAC. The kind of failure modes when it does can be exceedingly nasty to diagnose. Reference assemblies must come from the C:\Program Files (x86)\Reference Assemblies directory.

Looking at the .nuspec file for the Autofac nuget package you are trying to install, it supports two distinct targets. One is for DNXCore version 4.0.10-beta-22816. Hopefully you are not using it, that project is changing rapidly.

The other is .NET Portable, profile 259. Which allows your project to target .NET 4.5.x, Store, Phone80 and Phone81. What the blunt error message is telling you is that it has trouble finding that profile. Use Windows Explorer to have a look-see, the profile is stored in the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile259 directory. It has the required System.Runtime.dll reference assembly.

Well, surely it awol, I can't guess at the underlying reason.

They did make subtle mistakes in the .nuspec file. Do consider a more stable release of Autofac, you probably don't want to be a beta tester. And don't target 4.5.2, there is no point to that. It doesn't add anything interesting and forcing your user to update his .NET install is not very reasonable.

Share:
35,979

Related videos on Youtube

Tomas Aschan
Author by

Tomas Aschan

I am an engineering physicist from Stockholm, Sweden, with a passionate interest in programming and software architecture. Since creating my first program at age 12 (a VB6 app that showed a smiley when a button was clicked) I've spent many hours in front of my computer, watching screen casts and reading blogs about programming as well as trying all the new concepts out in my own programs. With a Master's degree in Engineering Physics from the Royal Institute of Technology in Stockholm, Sweden, I have deepened my modelling and reasoning skills, as well as had the opportunity to try out many different technologies and tools. I am currently working as a software engineer at Spotify, mostly massaging data to enable our internal research into developer productivity.

Updated on July 15, 2022

Comments

  • Tomas Aschan
    Tomas Aschan almost 2 years

    I'm trying to install the Autofac nuget package in my project using the command

    Install-Package -Prerelease Autofac
    

    but it fails with the error

    Install-Package : Failed to add reference to 'System.Runtime'. Please make sure that it is in the Global Assembly Cache.
    

    I've tried re-installing .NET Framework 4.5.2 (which is the version my project targets) but got the message ".NET Framework 4.5.2 is already installed". However, searching C:\Windows\assembly\ for System.Runtime.dll doesn't find any exact matches (although there are a few instances of System.Runtime.ni.dll, which (seem to indicate) that they are really the same assembly...).

    What can I do about this?

    project config

    Update: apparently I was confused about the location of the GAC. Amy enlightened me, and searching in C:\Windows\Microsoft.NET\assembly instead I do find System.Runtime.dll. Why doesn't Visual Studio?

  • Tomas Aschan
    Tomas Aschan almost 9 years
    This is a, for my understanding, very helpful writeup - thank you! I do, however, have a System.Runtime.dll in the directory you indicated. Might there be something wrong with it? How do I know? I managed to get out of my immediate problems by recreating the project files from scratch and copying the code files from a backup.
  • Nicholas Blumhardt
    Nicholas Blumhardt about 8 years
    I and another user hit this problem reproducibly with a different package SerilogTimings - worked around it by manually adding the reference, installing the package, then removing it again. Seems like a tooling issue with project.json-based packages.