135

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?

fordareh
  • 2,815
  • 2
  • 24
  • 39
Timwi
  • 61,190
  • 29
  • 155
  • 224
  • 1
    Can you clarify: does your project WORK without that reference? Is it in your web.config (see my answer)? – Basic Sep 06 '10 at 00:26
  • 4
    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. – Timwi Sep 06 '10 at 00:34
  • 1
    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. – qxotk Feb 09 '16 at 19:41

14 Answers14

108

Best way is to use NuGet package manager.

Just update the below MVC package and it should work.

enter image description here

sandeep talabathula
  • 3,008
  • 3
  • 26
  • 37
  • 4
    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). – jahu Feb 10 '15 at 10:54
  • 2
    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. – ceetheman Dec 04 '15 at 18:50
  • 1
    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. – qxotk Feb 09 '16 at 19:36
  • 1
    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.Mvc – Michael Davidson Jun 05 '18 at 13:48
107

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.

jahu
  • 4,899
  • 2
  • 35
  • 55
  • 1
    +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. – qxotk Feb 09 '16 at 19:30
  • 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 version – NJS Aug 20 '19 at 19:18
62

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.

Patrick Hofman
  • 143,714
  • 19
  • 222
  • 294
  • 1
    This get the reference for me, though I'm sure I've previously added this reference through the Framework Assemblies list. – Zarepheth Mar 26 '13 at 19:32
  • 9
    Not really good solution if you work in a team with VCS. Absolute paths are evil in this case. – Denis The Menace Oct 16 '14 at 09:21
  • Definitely agree that this is a bad solution in any kind of team development environment because of the hard-coded absolute path dependency. – Craig Feb 03 '15 at 23:19
  • 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. – vapcguy Aug 21 '18 at 20:10
  • This really helped; but Microsoft should have made this much more clean and easy.... – JosephDoggie Aug 28 '18 at 15:05
  • @vapcguy 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:**) – kebbaben Dec 05 '19 at 13:17
  • @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. – vapcguy Dec 08 '19 at 19:14
28

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.

fordareh
  • 2,815
  • 2
  • 24
  • 39
  • 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. – qxotk Feb 09 '16 at 19:38
11

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.

Uwe Keim
  • 36,867
  • 50
  • 163
  • 268
Alican
  • 141
  • 1
  • 3
  • 1
    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. – TTT Apr 10 '13 at 23:00
  • 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. – qxotk Feb 09 '16 at 19:39
5

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

zety
  • 136
  • 2
  • 4
5

"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.

eglasius
  • 34,909
  • 4
  • 58
  • 105
  • I don’t often say “this assembly is missing from the list” unless I’m sure of it. – Timwi Sep 06 '10 at 13:27
  • @Timwi 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: http://weblogs.asp.net/scottgu/archive/2009/10/29/add-reference-dialog-improvements-vs-2010-and-net-4-0-series.aspx#7242495 – eglasius Sep 06 '10 at 16:06
  • So are you saying that clicking the Name header sorts things for you? Does nothing here on my machine... – Roman Starkov Sep 08 '10 at 08:37
  • 1
    @romkyns it only works after all assemblies in the list have loaded. – eglasius Sep 08 '10 at 15:32
5

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.

Iman
  • 439
  • 4
  • 19
  • 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. :) – vapcguy Aug 21 '18 at 20:47
3

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.

Timwi
  • 61,190
  • 29
  • 155
  • 224
  • 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. – eglasius Sep 06 '10 at 16:10
  • @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. – Roman Starkov Sep 07 '10 at 12:18
  • @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. – eglasius Sep 07 '10 at 17:01
2

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.

Prof Von Lemongargle
  • 3,488
  • 26
  • 28
2

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

Md Shahriar
  • 859
  • 6
  • 7
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.

Basic
  • 25,223
  • 23
  • 108
  • 188
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

user1005462
  • 229
  • 2
  • 6
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.

J.D. Mallen
  • 2,887
  • 3
  • 19
  • 27