Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

gac

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?

like image 478
Tomas Aschan Avatar asked Jul 20 '15 14:07

Tomas Aschan


2 Answers

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.

like image 144
Roboblob Avatar answered Nov 16 '22 10:11

Roboblob


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.

like image 17
Hans Passant Avatar answered Nov 16 '22 12:11

Hans Passant