0

I have a MVC5 project I am trying to solve some issues with where I am not getting intellisense on the System.Web.MVC components

In the Web.Config in my views folder I have the following;

<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.Configuration" />
        <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" />
        <add namespace="Helpers" />
        <add namespace="Common.Net.Mvc" />
        <add namespace="Common" />
        <add namespace="MvcSiteMapProvider.Web.Html" />
        <add namespace="MvcSiteMapProvider.Web.Html.Models" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

However when I then reference for example Url., ViewBag or Html.ActionLink etc(also if I reference my Common class which is a .resx generated file). I get errors saying they do not existing the current context.

I can compile and run the code successfully and the pages render just fine, it would be nice to eliminate these errors though and get the intellisense I usually get.

I am running VS2017 Community and I have the Razor extension installed and updated. I have intellisense on other projects it just seems to be this one.

Matthew Flynn
  • 3,661
  • 7
  • 40
  • 98
  • Typically: rebuild; Close all files; Close Visual Studio and reopen – Ashley Medway Oct 17 '17 at 16:06
  • Tried and its still causing an issue? Any other ideas? – Matthew Flynn Oct 17 '17 at 16:07
  • All NuGet packages are restored and correctly referenced? – Ashley Medway Oct 17 '17 at 16:13
  • Seem to be. There's no issue when running the program. Just annoying I can't get the intellisense? – Matthew Flynn Oct 17 '17 at 16:18
  • Clear any .vs hidden folders and .suo .user files. Is it problem with only one solution? If you create a new MVC project does it work? All else fails try Visual Studio in SafeMode? – Ashley Medway Oct 17 '17 at 16:19
  • Sorry Ashley, yes tried that but still nothing. Yes it I have intellisense on other projects, its just this one. there is a .vs folder outside the solution but its not hidden. I tried removing this also but it's still not registering. There couldnt be anything contained in the csproj could there? – Matthew Flynn Oct 19 '17 at 07:34

1 Answers1

2

Ok, After much searching and wasting of time, this answer here fixed the issue;

The name 'ViewBag' does not exist in the current context - Visual Studio 2015

Here is a run down of the steps I took (the removal and deletion of files may not be required);

  1. Delete the .suo and .csproj.user from the solution having the issues.
  2. Delete the hidden .vs folder form the route of the solution
  3. Delete the temp asp net files from

C:\Users\your.name.here\AppData\Local\Temp\Temporary ASP.NET Files

  1. Delete the files fro here;

C:\Users\your.name.here\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache

Note the above alone didn't fix so then I applied the following in conjunction witht he above.

  1. Compared the .csproj version info with that of the project with the issue and ammend (as it was indeed a project carried over form VS 2012) and as per the link above.

csproj Image

  1. Right click the solution -> 'Manage Nuget Packages...' -> Updates -> select all -> apply updates

This rebuilt the nuget references and the intellisense came back. Hopefully one day, somewhere this will help.

Matthew Flynn
  • 3,661
  • 7
  • 40
  • 98