Coder Perfect

In the namespace ‘System.Web.Mvc,’ the type or namespace name does not exist.


The development of the MVC3 solution proceeded smoothly, but I received the following problem in the browser:

CS0234: Compiler Error Message In the namespace ‘System.Web.Mvc,’ the type or namespace name ‘Html’ does not exist (are you missing an assembly reference?)

Source Error:
Line 25:         <add namespace="System.Web.Mvc" />
Line 26:         <!--<add namespace="System.Web.Mvc.Ajax" />-->
Line 27:         <add namespace="System.Web.Mvc.Html" />
Line 28:         <add namespace="System.Web.Routing" />
Line 29:         <add namespace="System.Web.WebPages" />

I used NuGet to install the solution’s packets and set up MVC3 for all projects. Is System.Web.Mvc.Ajax, System.Web.Mvc.Html, and other libraries included in MVC3? I’m not sure why I’m getting this problem.

I have System in my References folder. Web.Mvc

Runtime version: v4.0.30319,



<?xml version="1.0" encoding="utf-8"?>
  For more information on how to configure your ASP.NET application, please visit
    <!-- For more information on Entity Framework configuration, visit -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="webpages:Version" value="" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <compilation debug="true" targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
        <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" />
    <httpRuntime targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <machineKey compatibilityMode="Framework45" />
    <profile defaultProvider="DefaultProfileProvider">
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
    <membership defaultProvider="DefaultMembershipProvider">
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
    <roleManager defaultProvider="DefaultRoleProvider">
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
    <validation validateIntegratedModeConfiguration="false" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SportStore;Integrated Security=True;Pooling=False;" providerName="System.Data.SqlClient" />

The System from MSDN. Web.Mvc is a namespace for web applications.

file packages.config:

<?xml version="1.0" encoding="utf-8"?>
  <package id="EntityFramework" version="5.0.0-rc" />
  <package id="jQuery" version="1.7.2" />
  <package id="jQuery.UI.Combined" version="1.8.11" />
  <package id="jQuery.Validation" version="1.9" />
  <package id="Microsoft.AspNet.Mvc" version="3.0.20105.1" />
  <package id="Microsoft.AspNet.Providers.Core" version="1.0" />
  <package id="Microsoft.AspNet.Providers.LocalDB" version="1.0" />
  <package id="Microsoft.AspNet.Razor" version="1.0.20105.408" />
  <package id="Microsoft.AspNet.WebPages" version="1.0.20105.408" />
  <package id="Microsoft.Web.Infrastructure" version="" />
  <package id="Modernizr" version="2.0.6" />
  <package id="Moq" version="4.0.10827" />
  <package id="Ninject" version="" />

Asked by J.Olufsen

Solution #1

Set the property of those files to Copy Local = True after cleaning your solution.

To set the Copy Local property to True or False, click the button below.

To see the References node in Solution Explorer, click the Show All Files button.

Answered by Toffee

Solution #2

TWO of my solutions have web projects that have uninstalled MVC on their own for any reason. They both work now after I installed it from Nuget. This occurred following the installation of a recent round of Windows updates, which framework changes for the version I was using (4.5.1).

The following is an excerpt from the.Net Web Development and Tools Blog:

My build was broken by Microsoft’s Asp.Net MVC Security Update MS14-059!

Answered by Chris

Solution #3

This one usually gets me when I’m running from IIS and the default site’s app pool is configured to.NET 2.0. When utilizing IIS from Visual Studio, a virtual directory is created, but the application is still executed within the normal site’s app pool. If you’re using the built-in web server, verify sure you’re using the correct version of.NET by right-clicking on your web project and going to properties. Check the.NET version of your app pool in IIS.

Following up on my previous comment regarding how the project was formed, are you included the assemblies appropriately, as seen below (from the default web.config file generated by the MVC3 project template in VS10):

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

Answered by BlackSpy

Solution #4

MVC must be updated.

Answered by Matt

Solution #5

I encountered the similar issue; in my case, I was referring the new System.Web.Mvc.dll from a lib folder without having “Copy Local” set to true. The program then reverted to the GAC version, which didn’t include the right namespaces (Html, Ajax, etc.) and was giving me the run time error.

Answered by Peter Munnings

Post is based on