C# – Visual Studio 2008 doesn’t recognize Lambda Expression Syntax


I recently upgraded a Web Application Project (as well as some dependent projects) from .net 2.0 to .net 3.5 using the built in conversion tool. Everything works well such as using MS AJAX 3.5 vs. the external MS AJAX libraries in 2.0.

My problem occurs when I tried using the new Lambda Expression syntax. The compiler will not recognize Lambda Expressions as valid syntax. The target frame work version is set to 3.5 in all projects in the solution.I was also able to successfully use Lambda Expressions in a Library Project in the same solution.

The is the code that is giving me the error. Nothing too special.

ObjectFactory.Initialize(x => 


The specific errors I am getting are:

Error   102 Invalid expression term '>' D:\projects\bohlco\pmr\PMR\Web\App_Code\Bootstrapper.cs 13  41  D:\...\Web\

Any help would be greatly appreciated. I have been searching Google with little luck

Best Solution

If any of the page is being compiled by ASP.NET (i.e. you aren't pre-compiling the WAP), then you'll need to ensure that ASP.NET knows about the C# 3.0 (.NET 3.5) compiler. Ensure the following is in the web.config:

      <compiler language="c#;cs;csharp"
            type="Microsoft.CSharp.CSharpCodeProvider, System, Version=, Culture=neutral, PublicKeyToken=
         <providerOption name="CompilerVersion" value="v3.5"/>
         <providerOption name="WarnAsError" value="false"/>

Also, if you are hosting in IIS, ensure that the correct folder is set as an application, and that it is using ASP.NET v2.blah (not v1.1.blah).