s.k.paul
s.k.paul

Reputation: 7291

The type or namespace name 'Mvc' does not exist

I have recently installed visual studio 2013. After downloaded a sample project from web, while i run it, it gives me the following errors-

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

How to overcome this error?

Upvotes: 71

Views: 129176

Answers (6)

Lars Kristensen
Lars Kristensen

Reputation: 1495

We sometimes experience these error messages with references to Nuget packages that are installed. This mostly happens when a project or solution is fetched from Source Control to a new folder.

Visual Studio shows the error:

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

However, in the code, the line with using System.Web.Mvc does have a red squiggle underneath, but the text is also fully white, indicating that VS does recognize the namespace.

The solution we have found, is:

  1. Close Visual Studio
  2. Navigate to the path of the Project/Solution in Explorer
  3. Iterate through all sub-folders and delete all bin and obj folders.
  4. Re-open the project/soltuion in Visual Studio, and Rebuild all projects.

Upvotes: 0

Nii N.
Nii N.

Reputation: 11

Year 2022 Answer:

delete the line:

using System.Web.Mvc;

and replace with:

using Microsoft.AspNetCore.Mvc;

Upvotes: 1

Aashish Malviya
Aashish Malviya

Reputation: 9

Including MVC controller and Model in the project resolved the issue.

Upvotes: 0

Rohan Rao
Rohan Rao

Reputation: 2603

Sometimes the package version conflict becomes an issue where if you have the MVC package installed then it shows the namespace error.

Here is how I solved it:

  • Open Package Manager Console (Tools > NuGet Package Manager > Package Manager Console)
  • Type uninstall-package Microsoft.AspNet.Mvc
  • Type install-package Microsoft.AspNet.Mvc

So this will give your package a fresh start, you will have all new MVC references and no errors.

Upvotes: 4

Jason Evans
Jason Evans

Reputation: 706

My solution was to simply open up the nuget package manager console and run the command update-package -reinstall Microsoft.AspNet.Mvc

Upvotes: 47

Andrei V
Andrei V

Reputation: 7496

The source of your error may be that you do not have a reference to the MVC framework library. A simple solution is to add this reference trough Nuget. The MVC library will be installed in your bin directory and, if needed, all the references will be added to your project.

Either browse for the MVC package (Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution) or install it using the Nuget console (Tools -> Nuget Package Manager -> Package Manager Console) by entering Install-Package Microsoft.AspNet.Mvc. You can find additional information on the official Nuget page for AspNet.Mvc.

Upvotes: 97

Related Questions