Visual Studio 2008 does not recognize Lambda Expression syntax

I recently upgraded my 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, for example using MS AJAX 3.5 versus external MS AJAX libraries in 2.0.

My problem comes when I tried to use the new Lambda Expression syntax. The compiler will not recognize Lambda Expressions as valid syntax. The target frame working 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.

This is the code that is giving me the error. Nothing special.

ObjectFactory.Initialize(x => 
        {
            x.ForRequestedType<IUnitIdSequencingService>().TheDefaultIsConcreteType<UnitIdSequencingService>();
            x.ForRequestedType<IGadgetDAO>().TheDefault.Is.OfConcreteType<GadgetDAO>().WithCtorArg("instance").EqualToAppSetting("OSHAInspectionManager");

        });

      

The specific errors I am getting are as follows:

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 searched google with little luck

+1


source to share


4 answers


If any page is compiled by ASP.NET (i.e. you are not pre-compiling WAP), then you need to make sure ASP.NET knows about the C # 3.0 (.NET 3.5) compiler. Make sure web.config

the following is stated:

<system.codedom>
   <compilers>
      <compiler language="c#;cs;csharp"
            extension=".cs"
            warningLevel="4"
            type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=
         <providerOption name="CompilerVersion" value="v3.5"/>
         <providerOption name="WarnAsError" value="false"/>
      </compiler>
   </compliers>
</system.codedom>

      



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

+7


source


I don't have much experience with the VS 2008 conversion tool, but I know that other project conversion tools have had "problems". I would recommend that you compare the .csproj file for your "broken" project with the one that works. The conversion utility may have broken something in your project. You can also try creating a new project and copying all source files.



0


source


a couple of hoops you need to skip with existing re reference projects, TBH I found it easier to just create a new project and add my existing source files to the new project.

0


source


My guess is that the parameter of the method you are passing the lambda takes a delegate as a parameter?

If that's true, you will need to overlay the lambda as a specific delegate type. This is pretty confusing, but what you need to know is that the lambda may not always be outputted correctly, so you need to drop it or change the method signature to accept certain types of delegates.

try this:

ObjectFactory.Initialize((Action<T>)(x => // where T is the typeof x
{
    // ...
}));

      

Also you can try to do some overloads for Initialize to accept certain types of delegates (for example Action).

If your method takes the type of a delegate of a specific type, you can ignore this answer :)

0


source







All Articles