问题
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:
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.
回答2:
I've faced with this issue, and have spent a lot of time, while figured out that App.Config file with empty configuration section in it was root of the evil. Simply remove App.Config, and all will work fine.
回答3:
The solution for me was to change the project type
- Unload the project
- Edit project
Swap the project GUID for this
ProjectTypeGuids: {E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
(This is an MVC3 project)
回答4:
For me this was ultimately caused by low disk space, presenting as a hailstorm of unusual and inexplicable random build errors.
来源:https://stackoverflow.com/questions/2560773/mvc-2-with-vs-2010-view-building-error-feature-anonymous-types-cannot-be-used