views:

125

answers:

3

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?

A: 

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.

Basiclife
OK, adding that XML to the Web.config works, but it doesn’t answer the question.
Timwi
"works" as in it provides the intellisense? I've edited my answer
Basiclife
A: 

"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
I don’t often say “this assembly is missing from the list” unless I’m sure of it.
Timwi
@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
So are you saying that clicking the Name header sorts things for you? Does nothing here on my machine...
romkyns
@romkyns it only works after all assemblies in the list have loaded.
eglasius
A: 

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
@Timwi 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
@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.
romkyns
@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