Search code examples
c#.netasp.net-core-mvcportable-class-libraryclass-library

Namespace not recognised after adding MVC6 project dependency to class library project


I have created default MVC6 (.net framework 4.6.1) project. It contains only ValuesController. Also in the same solution I have added Class Library (.net framework 4.6.1).

When I added reference of MVC6 project to class library I am not able to use any classes and namespaces.

Error CS0246 The type or namespace name 'mvc6test' could not be found (are you missing a using directive or an assembly reference?)

enter image description here


Solution

  • In your class library project, make sure that the required ASP.NET MVC nuget package is added, same way as your web project itself.

    enter image description here

    It will add the various missing assemblies in your class library project, like System.Web.Mvc, System.Web.Razor etc.

    Note: Just wondering why you need to access this MVC project from within a class library. Normally it's the other way around.