Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CS0234: Mvc does not exist in the System.Web namespace

I converted a ASP.net 4 webform project to Asp.net MVC4 according to Chapter 13 of the Professional ASP.NET 3.5 MVC, by Scott Hanselmen, Phil Haack, and Rob Conery, Published by Wiley Publishing, Inc. (ISBN: 978-0-470-38461-9). I also followed this blog. Now I can add Controllers, Views, etc. All the references are set properly. No build errors. But upon launching the converted project, I got compilation errors. I have mvc3 installed on the same machine. I even changed the reference to that. It still complain. Could you help? Thanks.

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

Source Error:

Line 109:            <namespaces>
Line 110:                <add namespace="System.Web.Helpers"/>
Line 111:                <add namespace="System.Web.Mvc"/>
Line 112:                <add namespace="System.Web.Mvc.Ajax"/>
Line 113:                <add namespace="System.Web.Mvc.Html"/> 

Source File: c:\Users\Jon\Documents\Visual Studio 2012\Projects\CMT\Apps\Branches\3.0\Web.config    Line: 111 
like image 350
user266909 Avatar asked Feb 12 '13 01:02

user266909


3 Answers

I had the same problem and I had solved it with:

1.Right click to solution and click 'Clean Solution'

2.Click 'References' folder in solution explorer and select the problem reference (in your case it seems System.Web.Mvc) and then right click and click 'Properties'.

3.In the properties window, make sure that the 'Copy Local' property is set to 'True'

This worked for me. Hope it works for someone else

Helpful Note: As it has mentioned in comments by @Vlad:

If it is already set to True:

  1. Set it False
  2. Set it True again
  3. Rebuild
like image 142
curiousBoy Avatar answered Oct 17 '22 06:10

curiousBoy


This problem can happen when you deploy your web application to a server, so you must check if you already installed MVC3.

Check if the folder C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 3 exists.

If it doesn't exist, you need to install it from http://www.microsoft.com/en-us/download/details.aspx?id=1491


If you wont to install you can add all DLLs locally in bin folder and add references to them this work fine if you host on server don't deploy ASP.NET Web Pages or MVC3.

like image 27
user2868064 Avatar answered Oct 17 '22 06:10

user2868064


Check your runtime tag inside the web.config, and verify you have something like this declared:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
.....
</runtime>
like image 40
amhed Avatar answered Oct 17 '22 06:10

amhed