Alex Rivera | Logout

Razor intellisense error: Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification

Asked 2011-12-19T22:20:35.287
32

Goal:

  • Use cshtml Razor templates to format data
  • Embed cshtml Razor templates in Class Library as Embedded Resources
  • Use Linq statements and extension methods in the cshtml template

I created a new class library project, then adapted Scott Hanselman's instructions on how to integrate MVC3 into a WebForms application to get it to work in a Class Library. Then I use the NuGet package RazorEngine to apply the template to an object.

So far it works great, with one hiccup: The intellisense does not recognize Linq statements or extension methods (a pretty important part of MVC) when editing cshtml files.

So for the following cshtml file:

@model Customer[]

@Model.Count()

@if (Model.Where(customer => customer.Type == 'New').Any())
{
    <span>Found at least one new customer.</span>
}

...it displays the following errors:

Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification

Feature 'lambda expression' cannot be used because it is not part of the ISO-2 C# language specification

Does anyone know what I'm missing? Thank you in advance--I've spent hours searching for the answer to this.


Some additional details

The following is my web.config in the Views folder:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section
Edit
Report

2 Answers

24

I tried all of the solutions to this error that I could find everywhere on the web and had no luck.

I finally got this error to disappear (and my IntelliSense to work) by copying the extra MVC configuration blocks from my project's web.config file to my project's app.config file.

Seems Visual Studio does not respect web.config (at least some of its parts) in a plain old C# library project.

My project's app.config file looks like this:

<appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <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.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  
answered 2012-12-13T14:34:15.263
4

After a couple hours more of tinkering, I found it had something to do with standard Visual Studio extensions not loading correctly.

I was receiving the error:

'VSTS for Database Professionals Sql Server Data-tier Application' package did not load correctly

I found the answer on on Microsoft Connect.

How to fix

1) Run the following installers from the Visual Studio media:

\WCU\DAC\DACFramework_enu.msi

\WCU\DAC\DACProjectSystemSetup_enu.msi

\WCU\DAC\TSqlLanguageService_enu.msi

2) Restart VS

Hope this can be of help to someone else.

answered 2011-12-20T19:15:50.473

Your Answer