Reputation: 13838
I upgraded my MVC application from MVC 3 to 5.2.2 and now I'm getting this error. I've made a brand new MVC project using the new project wizard and this works, and I've compared my /web.config
and Views/web.config
files across the two projects and don't see any differences that seem important.
Looking in the object browser, I see that there are in fact two different HtmlHelper
objects defined in System.Web.WebPages
and System.Web.Mvc
, which seems relevant:
But I'm not sure what to do with this fact.
Upvotes: 5
Views: 3888
Reputation: 29937
Make sure that your model
points to a real class, but this is probably because the MvcWebPageRazorHost
isn't registered or different versions are registered in the root web.config vs. the views web.config, often caused by updating MVC versions
I was getting several compiler errors anytime I opened a Razor View:
Type 'System.Web.Mvc.WebViewPage' is not defined.
'Context' is not declared. It may be inaccessible due to its protection level.
sub 'Execute' cannot be declared 'Overrides' because it does not override a sub in a base class.
'Html' is ambiguous, imported from the namespaces or types 'System.Web.WebPages, System.Web.Mvc'.
What fixed it was updating the webpages:Version
in the web.config:
From This:
<add key="webpages:Version" value="2.0.0.0" />
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
To This:
<add key="webpages:Version" value="3.0.0.0" />
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
Upvotes: 0
Reputation: 13838
After wrestling with this for hours and then posting the question here, I figured it out a minute later; I had specified a strongly typed model like this:
@ModelType IEnumerable(Of MyModel)
But around the same time that I upgraded to 5.2.2, I reorganized my namespaces so that MyModel
was in a different namespace, and this caused the problem. The fix was to change it to this:
@ModelType IEnumerable(Of NewNamespace.MyModel)
It would be nice if the compiler had caught this. It would never have occurred to me that it couldn't find my model object type at all but wouldn't just say so.
Upvotes: 7