Reputation: 7864
I'm on MVC 5, .NET 4.6, Visual Studio Professional 2015. I occasionally get a problem where VS decides it doesn't want to see certain references anymore. It's usually the ones directly related to MVC. The current issue is The type 'WebViewPage<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
This problem has been resolved in the past by uninstalling/reinstalling the MVC NuGet package, but that did not work this time. I've tried all of the following, nothing has worked. The project compiles and runs with no problems, it's only Intellisense that has a problem. Each of these steps was done with all views closed, they were reopened afterward. Each was also tested a second time closing VS in between.
System.Web.Mvc
is actually referenced and found (no yellow exclamation mark in the references list).System.Web.Mvc
is referenced in both Web.config
files (Views folder and root level), and that those references have the correct version 5.0.0.0
and the right PublicKeyToken
.Copy Local
and is in fact being copied when the project is built.bin
and obj
folders in each project in the solution.I have so many problems with Visual Studio package management.... How can I fix VS supposedly not finding the reference in views so that Intellisense works again?
Upvotes: 2
Views: 1295
Reputation: 7348
In the Error Message it is saying that it can't find System.Web.Mvc, Version=5.2.3.0
and then you mentioned that the config files are System.Web.Mvc, Version=5.0.0.0
So first try updating all System.Web.Mvc, Version=5.0.0.0
to Version=5.2.3.0
in both web.config and Views config files
[There is one reference to the library at the end of the views config file :-)]
If that doesn't work then Try This:
Make a backup of you config files first -
I had a similar issue after updating a project from MVC4 to MVC5.
The thing is that the update did not update the config files correctly.
You can create a New MVC Project with latest version and copy the config files from the new Project.
You can copy the <runtime>
section, from the Web.config
file.
And just copy the Whole of the Views config
file
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<!--Then copy over your View References-->
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>
Upvotes: 1