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

Guy picture Guy · Apr 22, 2010 · Viewed 19.2k times · Source

After converting a Hybrid ASP.NET MVC1 app to MVC2 I'm getting the following error when I try and run the application:

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

The allegeded culprit in the web.config file is System.Web.Mvc:

<namespaces>
    <add namespace="System.Web.Mvc"/>
    <add namespace="System.Web.Mvc.Ajax"/>
    <add namespace="System.Web.Mvc.Html"/>

So far my investigation seems to lead me to believe that version 2 of System.Web.Mvc is not installed or has not been picked up.

I've tried creating a File > New Project based on MVC 2 and that's picking up the new (v2) version of MVC. I've also converted some other projects (that were not hybrids) and they've converted without problem to MVC2.

I've also uninstalled MVC1 to try and remove references to it from the GAC. However, none of this has worked.

Any ideas?

Answer

Craig Stuntz picture Craig Stuntz · Apr 22, 2010

Make sure you have the binding redirect in your Web.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Web.Mvc" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

This forces MVC 2 even if MVC 1 is on the machine.

Also: MVC 1 does have a System.Web.Mvc namespace, so make sure you also have:

  <assemblies>
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>