Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mvc does not exist in the namespace system.web

Tags:

c#

I am using Visual Studio 2017 and getting this error:

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

on this line of code:

using System.Web.Mvc;

that using is needed for resolving SelectListItem on this line of code:

public static List<SelectListItem> VerificationMethod

I would expect adding an assembly reference would easily solve the problem.

Here is what I tried....

I tried adding an assembly reference by right clicking on the project and selecting Add -> Reference. System.Web.Mvc was not in the list of references to add.

Some other SO posts referenced package Microsoft.Aspnet.Mvc as resolving this. That package was not available either.

I tried this on the nuget console:

PM> Install-Package System.Web.mvc
Install-Package : Unable to find package 'System.Web.mvc'
At line:1 char:1
+ Install-Package System.Web.mvc
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

I also tried this:

PM> Install-Package Microsoft.aspnet.mvc
Package 'Microsoft.aspnet.mvc.5.2.6' already exists in project 'MySite'
Time Elapsed: 00:00:00.0549251
PM> 

I also tried this:

update-package -reinstall Microsoft.AspNet.Mvc

And got this error:

Install failed. Rolling back...
Package 'EntityFramework 6.1.0' does not exist in project 'DataAccess'

like image 405
Be Kind To New Users Avatar asked May 20 '18 00:05

Be Kind To New Users


2 Answers

Here is what we did that worked....

deleted all files and folders in the packages folder in the solution.

Ran:

Update-Package -safe -reinstall -IgnoreDependencies
Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0
like image 111
Be Kind To New Users Avatar answered Nov 14 '22 00:11

Be Kind To New Users


Will you please try the following:

In DataAccess Project> References > Right click on system.web.mvc and remove.

Change the project to DataAccess from package manager console, See the image

enter image description here

Then type in package manager console:

Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0

[EDIT by OP] This is what I got when I tried this:

PM> Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0


Attempting to gather dependency information for package 'Microsoft.AspNet.Mvc.5.2.3' with respect to project 'DataAccess', targeting '.NETFramework,Version=v4.5'
Gathering dependency information took 2.37 sec
Attempting to resolve dependencies for package 'Microsoft.AspNet.Mvc.5.2.3' with DependencyBehavior 'Lowest'
One or more unresolved package dependency constraints detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. If these packages are being updated this message may be ignored, if not the following error(s) may be blocking the current package operation: 'Microsoft.AspNet.Identity.EntityFramework 2.2.1 constraint: Microsoft.AspNet.Identity.Core (>= 2.2.1)', 'Microsoft.AspNet.Identity.EntityFramework 2.2.1 constraint: EntityFramework (>= 6.1.0)'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.AspNet.Mvc.5.2.3'
Resolved actions to install package 'Microsoft.AspNet.Mvc.5.2.3'
Found package 'Microsoft.AspNet.Mvc 5.2.3' in 'C:\ThePath\packages'.
Found package 'Microsoft.AspNet.Razor 3.2.3' in 'C:\ThePath\packages'.
Found package 'Microsoft.AspNet.WebPages 3.2.3' in 'C:\ThePath\packages'.
Found package 'Microsoft.Web.Infrastructure 1.0.0' in 'C:\ThePath\packages'.
Package 'Microsoft.AspNet.Razor.3.2.3' already exists in folder 'C:\THePath\packages'
Added package 'Microsoft.AspNet.Razor.3.2.3' to 'packages.config'
Successfully installed 'Microsoft.AspNet.Razor 3.2.3' to DataAccess
Package 'Microsoft.Web.Infrastructure.1.0.0' already exists in folder 'C:ThePath\packages'
Install failed. Rolling back...
Package 'Microsoft.Web.Infrastructure.1.0.0' does not exist in project 'DataAccess'
Removed package 'Microsoft.AspNet.Razor.3.2.3' from 'packages.config'
Executing nuget actions took 389.27 ms
Install-Package : Failed to add reference to 'Microsoft.Web.Infrastructure'.
  Reference unavailable.
At line:1 char:1
+ Install-Package Microsoft.AspNet.Mvc -Version 5.2.3.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
like image 1
Muhammad Awais Avatar answered Nov 14 '22 00:11

Muhammad Awais