Search code examples
asp.netrazorintellisensevisual-studio-2015asp.net-webpages

Visual Studio 2015 doesn't recognize imported namespaces in web.config for Razor


I have a website project containing numerous .cshtml (WebPages, not MVC) files and where i've defined a common set of namespaces in my web.config file like this

<system.web.webPages.razor>
  <pages pageBaseType="Composite.AspNet.Razor.RazorFunction">
    <namespaces>
      <add namespace="DinArv.Forms"/>
      <add namespace="DinArv.Web"/>
    </namespaces>
  </pages>
</system.web.webPages.razor>

After installing VS 2015 RTM, i'm suddenly getting 'The type or namespace ... could not be found' errors on types that exists in namespaces defined in web.config, while Resharper doesn't seem to have a problem. I can also still browse the pages fine and there are no build errors when i build my website. In my Visual Studio 2013 Intellisense is working as it should.

If i import the namespaces explicitly in the .cshtml file instead of web.config, VS 2015 is satisfied as well, but i really don't want to do that.

What is wrong, and how can i fix it?

VS 2015 screenshot


Solution

  • After hours and hours i accidentally stumbled upon what seemed to do the trick. My section group was defined like this, which VS 2013 had no problem with

    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor">
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor" requirePermission="false" />
    </sectionGroup>
    

    As soon as i added version-number to the types like this, Intellisense in VS 2015 lighted up. Grrrrr.... what a waste of time, but hopefully this can save someone else time.

    <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="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>