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

Failed to add reference to System.Diagnostics.Contracts #341

Closed
appel1 opened this issue Oct 25, 2016 · 25 comments
Closed

Failed to add reference to System.Diagnostics.Contracts #341

appel1 opened this issue Oct 25, 2016 · 25 comments

Comments

@appel1
Copy link

appel1 commented Oct 25, 2016

When I try to update a .NET 4.5 project to jint 2.10.2 NuGet fails with the following error.

Failed to add reference. The package 'jint' tried to add a framework reference to 'System.Diagnostics.Contracts' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance.

@Taritsyn
Copy link
Contributor

Hello, Johan!

Instead of updating the package try uninstall old version of package, and then install new version. In subsequent updates, this error should not occur.

@appel1 appel1 closed this as completed Oct 25, 2016
@marek-benes
Copy link

Hello,
I tried to uninstall package and then install a new version but this error still occur.

@iamcarbon
Copy link

Also experiencing this issue on a fresh install on net461.

@sebastienros sebastienros reopened this Oct 28, 2016
@sebastienros
Copy link
Owner

Can you provide some repro steps, with the type of project you are creating, how you are selecting the nuget package.

@samcic
Copy link

samcic commented Oct 29, 2016

I'm also experiencing this problem on a fresh install on .net 4.6.1. Environment:

  • Windows 10 Enterprise
  • Visual Studio 2015, version 14.0.25431.01 Update 3
  • Trying to install the jint package on a test project (which references and tests an ASP.NET MVC5 project). The test project is targeting .net 4.6.1.

Originally I was using jint version 2.10.0, and upgrading caused this problem. Uninstalling jint and trying a fresh install didn't solve the problem either unfortunately. In both cases I tried from the package manager console as well as the GUI version in VS. Here's the error dump from the package manager console:

Executing nuget actions took 3.54 sec
update-package : Failed to add reference. The package 'jint' tried to add a framework reference to 'System.Diagnostics.Contracts' which was not found in the GAC. This is possibly a 
bug in the package. Please contact the package owners for assistance.
At line:1 char:1
+ update-package jint
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Update-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand

@samcic
Copy link

samcic commented Oct 29, 2016

I'm not completely sure, but this might have something to do with this recent change:

9371178

This change involved moving the System.Diagnostics.Contracts dependency from "dependencies" to "frameworkAssemblies".

Unless I'm mistaken, "frameworkAssemblies" refers to assemblies that are in the GAC. So even if we have the System.Diagnostics.Contracts nuget package installed and updated, it doesn't look for it and instead tries to find it in the GAC (and it's not there). Does that sound reasonable?

@Taritsyn
Copy link
Contributor

@samcic The reason is explained here - #340

@appel1
Copy link
Author

appel1 commented Oct 29, 2016

If this is a choice between working on older versions of NuGet or the current version I think it makes more sense to choose the newer.

@Taritsyn
Copy link
Contributor

@marek-benes @samcic Try the following steps:

  1. Uninstall the Jint package
  2. Uninstall the System.Diagnostics.Contracts package
  3. Close "NuGet Package Manager" window
  4. File > Save All
  5. Install the Jint package

@Taritsyn
Copy link
Contributor

@appel1 It's not a choice between the old and new version of NuGet, but this update issue 2.10.0 | 2.10.1 -> 2.10.2.

@samcic
Copy link

samcic commented Oct 29, 2016

Thanks for your help @Taritsyn . Unfortunately the steps weren't successful (same error). I also made sure all the local files were deleted (in the solution "packages" folder) to make sure there was no trace of the old 2.10.0 install. I saved everything, built everything (build failed because of the missing jint stuff, but that's fine), then restarted VS as admin. I then tried to install jint fresh as a new package (not an update). Same error.

If I run a "gacutil -l" then it shows the System.Diagnostics.Contracts is indeed installed in the GAC, so the error message is rather confusing.

On the nuget reference page nuget reference page it mentions that the elements in "frameworkAssemblies" should be "The fully qualified assembly name". Perhaps culture, publickeytoken and processorarchitecture should be included? Just an idea.

Interestingly, if I create a fresh (bare bones) console app in VS and install jint, it works. I might try the same with fresh solution with an MVC project + test project like I have, to hopefully try to isolate the issue.

@Taritsyn
Copy link
Contributor

@samcic It seems, that this is a error in the NuGet Package Manager. Because these errors occur only .cproj projects in Visual Studio 2015 (in .xproj projects such errors do not occur).

@samcic
Copy link

samcic commented Oct 29, 2016

@Taritsyn I assume you mean .csproj rather than .cproj? If so, I created a bare-bones .csproj console app in VS 2015 targeting .net 4.6.1 and the error doesn't occur. I also created a bare-bones .xproj console app and jint installs fine there too.

Additionally, I created a bare-bones asp.net framework web app (mvc, .net framework 4.6.1, not .net core) project with a unit test project. I installed jsint 2.10.0 first, then upgraded to 2.10.2, and it worked fine.

The only time I see the error is in my "big/real" solution involving again an asp.net framework web app (mvc, .net framework 4.6.1, not .net core), with a .csproj unit test project. The error comes up in this solution regardless of whether I'm updating jint or installing it fresh. In this solution I'm often installing and updating other NuGet packages, and I haven't seen this kind of error with any other package.

Given all this I'm not convinced that it's an error with NuGet. I guess the first step would be to find some repro steps for this error that everyone can agree on. So far I'm not able to find repro steps based on a setting up a fresh VS project.

@Taritsyn
Copy link
Contributor

@samcic .csproj - I made a typo.

In this solution I'm often installing and updating other NuGet packages, and I haven't seen this kind of error with any other package.

Most likely, all these packages have been created by using NuGet.exe from a .nuspec file. Jint package was created by using dotnet.exe from a project.json file.

@sebastienros
Copy link
Owner

If you think that there is an error in Nuget, please give me a complete repro of the issue, or tell me to just use what @samcic said. I can talk to them directly and some other experts to analyze where it's coming from.

@Taritsyn
Copy link
Contributor

@sebastienros OK

@dalenewman
Copy link
Contributor

I had the same problem with an older solution with many, many projects in it.

I did NOT have issues when installing the package into a new solution.

In the new solution, Nuget added a reference to:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\Facades\System.Diagnostics.Contracts.dll

In my older solution, I could not reference the above dll without a getting a little warning sign next to it, so I referenced this one instead:

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Diagnostics.Contracts\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Diagnostics.Contracts.dll

The package installed okay then, and everything appears to be okay, but obviously it doesn't feel right :-)

I can't make any sense of it, but I thought adding a few more details to this thread may help.

@samcic
Copy link

samcic commented Nov 6, 2016

Another note: after the jint package successfully installed, I was then able to remove that "not feeling right" GAC System.Diagnostics.Contracts reference from the project and everything was still fine. So it almost seems like the reference just needed to be there just for the upgrade. All a bit strange.

@samcic
Copy link

samcic commented Nov 6, 2016

@dalenewman Referencing the assembly from the GAC folder as you described worked for me as well. Thanks for the information. In my case jint is only being used in a test project (no production code), so I consider this a sufficient solution to my problem.

@alastrange
Copy link

Also just experienced this issue.

@FlorianRappl
Copy link

Same here. Tried to update AngleSharp.Scripting. I know this is more than a MWE but the issue seems to be related to existing / larger repos and does not appear with fresh projects.

@njbmartin
Copy link

Also having this issue. To confirm, the issue only occurs on 2.10.2. 2.10.1 installs absolutely fine.

Targeting .NET 4.6.1

@chapeti
Copy link

chapeti commented Dec 16, 2016

Same issue here:

Failed to add reference. The package 'jint' tried to add a framework reference to 'System.Diagnostics.Contracts' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance.

Details :

  • Trying to update from 2.10.1 to 2.10.2.
  • Visual Studio 2015 Entreprise 2015 Update 3.
  • Target Framework: 4.5.2

@halex2005
Copy link

I had same issue in Visual Studio 2015 Update 3, .NET Framework 4.5.1. Tried to install jint v2.10.3 from scratch.

Steps to workaround the issue:

  • as @dalenewman wrote, I'd added assembly reference C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Facades\System.Diagnostics.Contracts.dll
  • install jint with nuget package manager, now it works!
  • I'd deleted assembly reference System.Diagnostics.Contracts.dll from project
  • profit

@lahma
Copy link
Collaborator

lahma commented Dec 24, 2018

Closing as there's a workaround and 3.x shouldn't suffer from this, and that's where development efforts are.

@lahma lahma closed this as completed Dec 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests