Project: VB.NET MVC5 w/ EF6, MvcScaffolding, and BootstrapEditorTemplates
Since this morning I don't get any intellisense for any of the built in MVC helpers, nor my custom ones in any of the Views in an Area. NOTE: I can still see Html.Encode, and Htm.DropDownList (NOT DropDownListFor<>) etc.
If I build it I recieve errors, though I can still browse the application correctly and see the correct editors and data.
@ModelType Quotes4YouVB.Request
@Html.EditorFor(Function(model) model.Urgency)
@Html.EditorFor(Function(model) model.Message)
I recieve the following errors among other similar ones.
'ModelType' is not declared. It may be inaccessible due to its protection level. 'ViewBag' is not declared. It may be inaccessible due to its protection level. 'EditorFor' is not a member of 'System.Web.WebPages.Html.HtmlHelper'. 'ValidationMessageFor' is not a member of 'System.Web.WebPages.Html.HtmlHelper'.
I've tried all the usual suspects:
Any ideas anyone? It seems odd that it's specific to /Areas/, it works completely fine in ~/Views/X/Y.vbhtml
Found the solution! I'm unsure why this specific thing causes this problem, but as with most VS issues I'm not gonna question it too much, just gonna go with it haha.
It relates to the System.Web.WebPages.Razor Host FactoryType section.
My ~/Views/Web.config has the following:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory,
System.Web.Mvc, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
...
</namespaces>
</pages>
</system.web.webPages.razor>
Specifically the Version=5.0.0.0 part. Because I'd just re-installed MVC 5.2.x from NuGet, so surely it should be 5.2.0.0?
I checked the Web.config in my ~/Areas/[AreaName]/Views/Web.Config and found that it had everything the same, except it read Version=5.2.0.0:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
I tried both in both files and found that wherever 5.0.0.0 is used then all intellisense works perfectly for those views.
So, the solution: Modify all Web.config files to use a compatible version for the factoryType. (5.0.0.0 works for me, though 5.2.0.0 does not)
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<!--<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.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.Routing" />
<add namespace="System.Web.Optimization" />
</namespaces>
</pages>
</system.web.webPages.razor>
I'm really unsure about why this is happening though, if anyone has any further information or a better solution to use 5.2.0.0 then please share :)