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

24,987

Solution 1

  • Restart Visual studio
  • Remove the assembly reference and re-add it
  • Do a clean and re-build
  • Try install Microsoft.AspNET.MVC from nuget package manager

Solution 2

in my case it worked only after I run in the Package Manager Console following command

PM> Install-Package Microsoft.AspNet.Mvc

My environment was:

1) Visual Studio 2017
2) Freshly created Angular 4 app
3) MVC 6 as a back end
Share:
24,987

Related videos on Youtube

davids
Author by

davids

I am in sales and code for fun on the side

Updated on December 05, 2020

Comments

  • davids
    davids over 3 years

    Whenever I try to compile my VS2015 application, I a long list of errors like:

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

    However, as soon as I double click the error to view the file, it opens the file, has a slight delay, then clears ALL the errors.

    If I proceed to try and build again, I get the same list of errors and the process repeats itself.

    UPDATE I forgot to mention that I have tried:

    1. following the advice in several other SO questions - to no avail
    2. ensuring the dlls are set to copy to local
    3. removing and re-adding references
    4. deleting dlls from the application and adding them back
    5. cleaning and rebuilding the application
    6. restarting the application and my computer

    What would cause this? How do I eliminate it?

    • Ian
      Ian about 8 years
      This is perhaps due to the heavy tasks which VS2015 do in background all the time and it cannot handle the big scope of your project. Try to reduce the amount of files in the project if there are too many.
    • ProgrammingDude
      ProgrammingDude about 8 years
      Have you tried restarting visual studio? Have you moved any files around from one folder to another?
    • EdSF
      EdSF about 8 years
      In that long list, try to scroll lower to things that look more like "real errors" (syntax, etc.). Also you may have updated a package in one project and not in related projects (mismatch). If all else fails, and the errors simply don't make sense , push that nuke button and simply restart VS (yes, I meant that, it's not a joke)...Hth.
    • Martin Dawson
      Martin Dawson about 8 years
      Your web.config references might be incorrect. Re downloading nuget packages may fix
    • Manish
      Manish over 7 years
      Unbelievable, restarting Visual Studio was indeed the answer. Had been wrestling with this for over 3 hours. Visual Studio Community 2015 update 3 with .NET framework 4.6.01055. System.Web.Mvc version is 5.2.3
  • davids
    davids about 8 years
    I have other MVC solutions that continue to work just fine, so I don't think it is an issue with MVC. I have tried all the others previously.
  • Nick
    Nick about 8 years
    It's usually not a issue that affects all MVC applications, rather your solution file has somehow had a path or config messed up that has broken the project. If you have tried these steps including the re-install of MVC from nuget then i am our of ideas sorry.
  • Harvey Darvey
    Harvey Darvey over 6 years
    Works for me, I had to force remove nuget package for MVC, Razor, and WebPages and reinstall them. After that it worked. For me it was not an issue with the machine, several machines had that issue.
  • Nirav Vasoya
    Nirav Vasoya almost 5 years
    I am getting the same error in my project, structure is, 1 project i have edmx and getting reference in another one Web project. is error related to the structure? or anything else? i have follow the same step which you mention but still facing the same issue. @Nick