The type or namespace name does not exist in the namespace ‘System.Web.Mvc’

Recently joining an MVC project (check out, build, run), Visual Studio raised the following error message:

CS0234: The type or namespace name ‘Html’ does not exist in the namespace ‘System.Web.Mvc’ (are you missing an assembly reference?)

The MVC project had System.Web.Mvc, System.Web.Mvc.Html, and other assemblies in its references.

web.config contained all the required namespace declarations

<add namespace="System.Web.Helpers"/>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Web.WebPages"/>

but still the error was raised.

Fortunately, the internetz already knew the solution for this problem:

Set the Copy Local flag for each of these assemblies to true.

In hindsight, the solution seems quite logical: if the MVC assemblies are not registered in the GAC, the MVC view compilation triggered by

<MvcBuildViews>true</MvcBuildViews>

cannot find the assemblies, which are expected in the GAC or in the /bin directory.

Of course, msbuild could retrieve their location (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\) from the project file 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: