Question

Please bear with me on this, since I am a Java developer just dipping a toe into the ASP.Net world

I started coding in an existing C# VS2012 codebase. It uses nuget and Newtonsoft is mentioned in the packages.config

When I right-click on Controllers > Add a new controller, I get the following error.

Could not load file or assembly 'nunit.framework, Version=2.2.4.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies.

The system cannot find the file specified.

Now looking around in Google, it seems the GAC is missing an NUnit assembly. Not sure what I should do about that. Should I get NUnit? Why is it looking for a certain version of nunit (& that too a very old one)?

Any help for me to resolve this problem will be highly appreciated!

Was it helpful?

Solution

When you click "Add new Controller' Visual Studio will try to complete the parse/build to populate a number of values in the window that it is supposed to show you (with the available Models and available Views). It looks like at least one of your projects is missing a dependency (probably your Unit Test project).

NUnit 2.2.4.0 is indeed a pretty old version, it doesn't even exist on NuGet yet (which would have been an easy fix). It makes sense that NUnit is not installed in the GAC, since you normally don't put everything in the GAC just because it seems to be possible. If you're willing to upgrade to the latest NUnit version, the easiest way is to add the NUnit NuGet package to your project through the Package Manager.

I would assume that when you'd open the project file for the project that is generating this warning in Notepad, you'd see a <hintpath> tag as a sibling of the NUnit Reference (it may not be there) which points to the folder where it is telling Visual Studio to look for NUnit.

I suggest you install the NUnit version your project is looking for from here and then update the reference in your project to point to the correct location. That should fix the issue.

As for your remark on the specific version, .NET Assemblies are compiled with a specific version number (usually set in the AssemblyInfo.cs) a reference in a project file can be to a specific version or to any assembly with that name (highlight the reference in the Solution Explorer and check the properties window (ctrl+w,p or alt+enter). You'll see a property "Specific Version" which in your case is set to "true" which caused Visual Studio to store the assembly version in the project file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top