Why is System.Web.Mvc not listed in Add References?
Asked Answered
N

14

145

Using C#, Visual Studio 2010.

There is a namespace called System.Web.Mvc documented on MSDN. The documentation for all the types in that namespace says that they are in System.Web.Mvc.dll.

However, when I go to Add Reference, “.NET” tab, this assembly is missing from the list. Why?

Naked answered 6/9, 2010 at 0:10 Comment(3)
Can you clarify: does your project WORK without that reference? Is it in your web.config (see my answer)?Sematic
I am not working on any project. I just wanted to help someone here on StackOverflow. I usually add a reference in order to look at the IntelliSense and/or the F12 for any type. In this case the desired assembly was missing from the list, so I asked why.Naked
NOTE to readers of this page - as of today (2015-02-09) the method for resolving this has changed over time - read all the answers - various version of VS.NET and .NET framework move the code referenced for MVC around into to different places.Valval
N
4

The desired assembly has appeared in the list now.

I can only speculate what caused it to appear, but I suspect it is the fact that I went FileNewProjectASP.NET Web Application, which I had never done before. It is possible that this caused some sort of late initialisation to happen and the list to be populated with additional assemblies for Web development.

Naked answered 6/9, 2010 at 13:29 Comment(3)
it was always surely always there, its ok :P ... see the comment I added to my answer, in the link it says: "The issue with the .net tab, is while the async is happening and its being refreshed, its not sorting in alphabetical order..." ... which is a new behavior to vs 2010, I never realized that until I saw your question.Titivate
@egl I just tested on my machine here (VS2010) and it's not in the list at all. I do get different sets of assemblies depending on Target Framework, but this one is never there.Stockbreeder
@romkyns try targeting .net 4, and doing what I mentioned in my answer. Also make sure to give it enough time to load, since it does an async load.Titivate
D
118

Best way is to use NuGet package manager.

Just update the below MVC package and it should work.

enter image description here

Dawna answered 1/6, 2014 at 4:49 Comment(5)
I've got to admit this is the right way to add reference to MVC in most cases (it should spare you the problems with running the app outside of Visual Studio that bad references might cause). However in big solutions which already containing MVC some projects, using the "Manage NuGet Packages for solution" to install the same version of the library is even better. The reason is, if you just install them from NuGet package manager, you might end up with version incompatibility (the manager will usually offer you the newest version).Levitus
I've used that solution for a project using MVC 4 that couldn't compile with Visual Studio 2015. It also ensures that the project libraries are uniform across all developpers.Cadena
I had this problem with a box that had only VS2015 on it, while other team members had VS2013 - which might have them referencing the old location (no build errors) while I didn't have the code and build errors. Of Note, as of today, I could not find Microsoft.Web.Mvc - which were the references that caused the issue. In the answer from @forderah sheds the light on the fact that the name is different in NuGet. Microsoft.Web.Mvc is now Microsoft.AspNet.Mvc, which also pulls in the dependencies listed in his/her answer.Valval
I even had this problem in VS2017, and this fixed it. Not sure why VS2017 told me that it thinks that the assembly that needs to be referenced is System.Web.Mvc while it's actually looking for Microsoft.AspNet.MvcJory
I'd go one step further and say you need to Manage Packages for the Solution. If you right-click on a Project and Select "Manage NuGet Packages..." then it will only be for that Project. If you right-click the Solution and Select "Manage NuGet Packages for Solution..." then you will see what Packages are Installed for All Projects within the Solution - along with which Version. In our case we had a mix of Different Version Numbers and Packages that were Not Installed in Projects where they were Referenced. From here we Installed "Microsoft.AspNet.Mvc" (by MS).Grasping
L
111

In VS Express 2012 I couldn't find System.Web.Mvc in the "assemblies" tab, but after a bit of searching I found out that I need to look into "assemblies\extensions" tab rather than the default "assemblies\framework" tab.

Levitus answered 7/6, 2013 at 12:17 Comment(2)
+1 for you because you found the root cause of the problem I had. I chose to use the NuGet install method proscribed below, and I will comment there what I did.Valval
I tried this method in Visual Studio Community 2015 but I got a runtime error related to version incompatibility (Could not load file or assembly...The located assembly's manifest definition does not match the assembly reference). I have another project in my solution referencing a different version, and this method only allowed me to add a reference to System.Web.Mvc, Version=4.0.0.0. The NuGet install method added the correct versionSanity
M
63

I had the same issue and wasn't able to locate the System.Web.MVC reference assembly.

Finally found out and it was located inside the following location.

Note if your VS was installed in C: (Sometimes the MVC.dll is not in the default location which everybody talk about, i mean the "Reference Assemblies" folder located in the C: drive.)

if its not there, it should definitely be in here:

\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll

So add the dll through navigating or the browse tab in the add reference menu.

Marshy answered 15/4, 2012 at 17:0 Comment(7)
This get the reference for me, though I'm sure I've previously added this reference through the Framework Assemblies list.Cycloid
Not really good solution if you work in a team with VCS. Absolute paths are evil in this case.Guanaco
Definitely agree that this is a bad solution in any kind of team development environment because of the hard-coded absolute path dependency.Aronson
The way you get around that is to ensure everyone is using the same path for the DLL. It shouldn't be a problem if all team members have the assemblies installed at that location, as they should. Alternatively, the DLL can be copied from that path, and placed directly into the project, so it has a relative path. But either way, just having the location of where that DLL is, is a good starting point.Mufinella
This really helped; but Microsoft should have made this much more clean and easy....Flemings
@Mufinella You can't expect everyone to have the assemblies on the same location. Then what happens when one or more people have their OS installed on a different driver from the rest of the team? (eg. D: or E:)Kristopherkristos
@kebbanen Everyone on the team needs to have the same Windows image, home drive/documents folder, & Visual Studio installation practices. This should be a given. If it’s not, your development shop has larger issues.Mufinella
W
30

You can also add this from the Nuget Package Manager Console, something like:

Install-Package Microsoft.AspNet.Mvc -Version 4.0.20710.0 -ProjectName XXXXX

Microsoft.AspNet.Mvc has dependencies on:

  • 'Microsoft.AspNet.WebPages (≥ 2.0.20710.0 && < 2.1)'
  • 'Microsoft.Web.Infrastructure (≥ 1.0.0.0)'
  • 'Microsoft.AspNet.Razor (≥ 2.0.20710.0 && < 2.1)'

...which seems like no biggie to me. In our case, this is a class library that exists solely to provide support for our Mvc apps. So, we figure it's a benign dependency at worst.

I definitely prefer this to pointing to an assembly on the file system or in the GAC, since updating the package in the future will likely be a lot less painful than experiences I've had with the GAC and file system assembly references in the past.

Widthwise answered 18/5, 2013 at 8:27 Comment(1)
I used this method, and I agree with not using local absolute paths in the references. I used the NuGet package manager, adding the package and dependencies fixed the issue on my VS2015-only box.Valval
T
12

I have had the same problem and here is the funny reason: My guess is that you expect System.Web.Mvc to be located under System.Web in the list. But the list is not alphabetical.

First sort the list and then look near the System.Web.

Tiein answered 11/9, 2012 at 14:38 Comment(2)
Also make sure that you are getting the correct version. In my case System.Web.Mvc v2 and v4 are there, and they too are not next to each other.Glassman
Had same problem finding System.Web.Mvc for same reasons. I went with Microsoft.AspNet.Mvc instead, ensuring to check to see what the other projects in my solution were using in regard to version number.Valval
J
7

I solved this problem by searching "mvc". The System.Web.Mvc appeared in search results, despite it is not contained in the list.

Jongjongleur answered 19/7, 2014 at 9:9 Comment(0)
T
6

"OK, adding that XML to the Web.config works, but it doesn’t answer the question"

It should be there. By default the add references list seems to be ordered, but its not the case. Hit the name header and look again.

Titivate answered 6/9, 2010 at 10:17 Comment(4)
I don’t often say “this assembly is missing from the list” unless I’m sure of it.Naked
@Naked I figured, but given the other answer, that there is v. little chance that its not there with vs 2010 installed and that in my case I always have found what I need in the references list without ever hitting the name header I had to say it ... in fact, I now know why I never had to before and in vs 2010 I do - see the first comment: weblogs.asp.net/scottgu/archive/2009/10/29/…Titivate
So are you saying that clicking the Name header sorts things for you? Does nothing here on my machine...Stockbreeder
@romkyns it only works after all assemblies in the list have loaded.Titivate
S
6

Check these step:

  1. Check MVC is installed properly.
  2. Check the project's property and see what is the project Target Framework. If the target framework is not set to .Net Framework 4, set it.

Note: if target framework is set to .Net Framework 4 Client Profile, it will not list MVC reference on references list. You can find different between .Net Framework 4 and .Net Framework 4 Client Profile here.

The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features. This enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.

Styliform answered 12/3, 2012 at 8:53 Comment(1)
This was a good tip. When I went to my project's properties, it only listed .NET Core 1 and 2. No .NET Framework 4.x. I was missing assemblies in my list. Turns out it was how I built my project - I chose the wrong option - to use .NET Core instead of .NET Framework. Now I know the difference. :)Mufinella
N
4

The desired assembly has appeared in the list now.

I can only speculate what caused it to appear, but I suspect it is the fact that I went FileNewProjectASP.NET Web Application, which I had never done before. It is possible that this caused some sort of late initialisation to happen and the list to be populated with additional assemblies for Web development.

Naked answered 6/9, 2010 at 13:29 Comment(3)
it was always surely always there, its ok :P ... see the comment I added to my answer, in the link it says: "The issue with the .net tab, is while the async is happening and its being refreshed, its not sorting in alphabetical order..." ... which is a new behavior to vs 2010, I never realized that until I saw your question.Titivate
@egl I just tested on my machine here (VS2010) and it's not in the list at all. I do get different sets of assemblies depending on Target Framework, but this one is never there.Stockbreeder
@romkyns try targeting .net 4, and doing what I mentioned in my answer. Also make sure to give it enough time to load, since it does an async load.Titivate
C
4

I didn't get System.Web.Mvc in VS 2012 but I got it in VS 2013. Using AddReference Dialog, enter image description here

Or, You can find this in your project path,

YourProjectName\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll

Corgi answered 24/7, 2018 at 20:28 Comment(1)
Great tip showing where to find in the existing project path. Thx!Pinon
N
3

This has changed for Visual Studio 2012 (I know the original question says VS2010, but the title will still hit on searches).

When you create a VS2012 MVC project, the system.web.mvc is placed in the packages folder which is peer to the solution. This will be referenced in the web project by default and you can find the exact path there).

If you want to reference this in a secondary project (say a supporting .dll with filters or other attributes), then you can reference it from there.

Numerology answered 4/10, 2012 at 19:49 Comment(0)
S
0

I believe you'll find the MVC assembly is referenced in the web.config file, not in the project itself.

Something like this:

<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </assemblies>
</compilation>

To respond to your comment;

The best answer I can give is from here:

The add element adds an assembly reference to use during compilation of a dynamic resource. ASP.NET automatically links this assembly to the resource when compiling each code module.

Sematic answered 6/9, 2010 at 0:16 Comment(2)
OK, adding that XML to the Web.config works, but it doesn’t answer the question.Naked
"works" as in it provides the intellisense? I've edited my answerSematic
M
0

it can be installed separated, and it's not included in framwork, choose tab list "extensions" and it exists there are and more other libs, all is ok not needed to used old libs etc, exists old 20 30 and 4001

Mccain answered 9/11, 2016 at 9:54 Comment(0)
P
0

If you got this problem in Visual Studio 2017, chances are you're working with an MVC 4 project created in a previous version of VS with a reference hint path pointing to C:\Program Files (x86)\Microsoft ASP.NET. Visual Studio 2017 does not install this directory anymore.

We usually solve this by installing a copy of Visual Studio 2015 alongside our 2017 instance, and that installs the necessary libraries in the above path. Then we update all the references in the affected projects and we're good to go.

Proportional answered 31/5, 2018 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.