views:

273

answers:

1

I have a shared project where I store all of my custom EditTemplates and DisplayTemplates. This is a regular C# class library project with the views all tagged as embedded resources. The target framework of this project is ".Net Framework 4".

Inside the /Views/ folder I have included this web.config file so I get MVC 2 intellisense when working with the .aspx and .ascx files:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc,     Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral,   PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />  
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode"    type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

Normally I have no problems with this setup but once and while I get an error when I compile my views:

Error 3 Feature 'anonymous types' cannot be used because it is not part of the ISO-2 C# language specification

for a template that looks like:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>
<%
    string displayText = string.Empty;

    if (Model != null)
    {
        if (DateTime.Parse(Model.ToString()) != DateTime.MinValue)
            displayText = DateTime.Parse(Model.ToString()).ToShortDateString();
    }
%>

<%= Html.TextBox("", displayText, new { @class = "date-box" })%>

Most of the time this error just goes away. I've learned to deal with it but right now its causing some issues. Any idea of what causes the "Error 3 Feature 'anonymous types' cannot be used because it is not part of the ISO-2 C# language specification" error and how I can fix this?

+1  A: 

Somehow your IDE experience is causing the 4.0 C# compiler to be limited to features allowed in the 2.0 version of the compiler. This can be done using the langversion switch. For example

csc /langversion:ISO-2 ...

Full Documentation: http://msdn.microsoft.com/en-us/library/f4ckecs0.aspx

I'm unfamiliar with how compilation works for Asp.Net MVC but somewhere in your project system you've asked to be limited to the 2.0 framework. My first guess would be to look at the project page of the project and make sure it's not targeting 2.0.

JaredPar