The Type or Namespace Name Does Not Exist in the Namespace 'System.Web.Mvc'

The type or namespace name 'Mvc' does not exist

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.

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


  • 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

Mvc does not exist in the namespace system.web

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

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

Solved by doing this:

https://stackoverflow.com/a/26772349/3448308

It downgraded to older version and worked ...

Thanks to @Pavan Chandaka

EDIT: i had to downgrade to 5.2.0 to make it work again (it was 5.2.3 (last release))

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

The problem was fixed here: https://github.com/OmniSharp/omnisharp-vscode/issues/3990

When my dotnet core sdk updated to 3.1.401 it made it so that I had to change a setting in vscode involving mono.

I went to File > Preferences > Settings then searched "omnisharp use global mono" and changed the resulting value from "auto" to "never." This stopped the errors when linting.

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

Clean your solution and then set the property of those files to Copy Local = True.

To set the Copy Local property to True or False

In Solution Explorer, click the Show All Files button to display the References node.

  • Open the References node for the project.
  • Right-click a reference in the References list, and click Properties.
    The properties associated with that reference appear in a list in the Properties window.
  • In the Properties window, change the Copy Local property to True or False.

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

It seems you're missing System.Web.Mvc.dll in bin folder

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' .NET MVC 5 to .NET Core 3.1 MVC Migration

In ASP.NET Core 3.1, the main namespace for a MVC application is Microsoft.AspNetCore.Mvc. Try using that instead of System.Web.Mvc.

Error Handling in ASP.NET Core

That said, as far as error handling in particular is concerned, the approach has changed quite a bit from ASP.NET Framework, and the HandleErrorInfo class no longer exists. For more information on the new approach, see Handle errors in ASP.NET Core. Instead of using the HandleErrorInfo class to retrieve information on an exception, for instance, you now use an implementation of IExceptionHandlerPathFeature—though there's a bit more to it than that, as covered in the documentation.

Migration Plan

Ultimately, this is just the first of many differences you're likely to run into when migrating to ASP.NET Core. Given that, I'd recommend reading through Microsoft's Migrate from ASP.NET to ASP.NET Core guide, which provides a useful summary of what has changed, and how to approach the migration.

Reference Project

In addition, assuming you're using Visual Studio, I'd recommend creating a new ASP.NET Core Web Application project, which will create a basic ASP.NET Core 3.1 MVC application. This can be really useful to reference when performing a migration, as it establishes what a "text book" implementation should look like, and gives you an idea of what's changed and how to approach similar problems in the new framework.

Final Thoughts

Ultimately, a lot of the changes in ASP.NET Core are simply a matter of adding references to the correct NuGet packages, updating the namespaces, and, in a few cases, updating code to match changes in the class signatures. Still, there remain a number of areas where the old approaches (and the classes that supported them) no longer exist—as is the case here—and thus require additional thought and care.

Positively, this is a lot easier with .NET Core 3.x than it was with previous versions, as Microsoft has done a ton to close the feature parity gap between .NET Framework and .NET Core over the last four years. And, once you've finished the migration, I think you'll find your new site much cleaner and easier to maintain.

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

OK, so I was able to boil the problem down to the following:
You have something like a self-hosted WebAPI/console application, and want to use Razor to
create HTML pages. Those Razor templates use some classes from Sytem.Web.WebPages
or System.Web.Mvc or the like, which are bundled in their own assemblies.

But those classes are used only in the views. When starting in debug mode you will see that
the runtime does not load those assemblies, regardless if they are added to the project
references or not. It appears when compiling razor files, the compiler sees only namespaces
from loaded assemblies, so you get those X-not-found exceptions. You will have to load the needed
assemblies manually (and make sure a compatible version is found).

One short example:

We have a layout.cshtml and an index.cshtml. We use some HTML helper functions to create a form.
layout.cshtml:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<div class="main-content">
@RenderBody()
</div>
</body>
</html>

index.cshtml:

@using System.Web.Mvc;
@{
Layout = "layout";
}
<div class="box-body">
<h1>Hello!</h1>
<p>
Got Html? @MvcHtmlString.Create("<b>FooBarBaz</b>")
</p>
</div>

Source code where the razor files are parsed and HTML output is handled. For simplicity it
is assumed all files are near the executable; you may need to adapt to your storage structure:

//load required assembly. By using the short name here the runtime uses
//the the first one that matches. See MSDN for further information
System.Reflection.Assembly.Load("System.Web.Mvc");
//cache the template before the actual page to avoid a null reference exception
RazorEngine.Razor.GetTemplate(File.ReadAllText("layout.cshtml"), "layout");
var result = RazorEngine.Razor.Parse(File.ReadAllText("index.cshtml"));
Console.Write(result);

You then need to add the assembly to your project (in this example possible via nuget, Microsoft.AspNet.Mvc) and maybe manually add the reference (if it isn't added automatically). This way you get the (hopefully) right version copied along with your executable.

One final note:

Nearly all goodies available in an ASP.Net MVC view (@Html for example) are objects injected by
the ASP.NET pipeline and therefor not available when using Razor directly. (I don't know if or how
it is possible to pass objects to Razor besides models) So most classes and functions
from the System.Web.Mvc or System.Web.WebPages namespaces are probably out of reach
(without reconstructing parts of ASP.NET).

The used @Layout and @RenderBody() are usually some of those ASP.NET helpers too. But as they are pretty common, it appears the author recreated their function manually in the RazorEngine parser.

Ajax' does not exist in the namespace 'System.Web.Mvc'

I think you are referencing an older version of System.Web. Right-click the project in vs and select 'Manage NuGet Packages' then search for Asp.Net MVC and click install. This will install the proper System.Web with Ajax. You can remove the six other binaries downloaded if they are not needed.



Related Topics



Leave a reply



Submit