views:

777

answers:

4

Hello,

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 => 
        {
            x.ForRequestedType<IUnitIdSequencingService>().TheDefaultIsConcreteType<UnitIdSequencingService>();
            x.ForRequestedType<IGadgetDAO>().TheDefault.Is.OfConcreteType<GadgetDAO>().WithCtorArg("instance").EqualToAppSetting("OSHAInspectionManager");

        });

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

A: 

I don't have much experience with the VS 2008 conversion tool, but I know other project conversion tools have had "issues". I'd recommend you compare the .csproj file for your 'broken' project to one that is working. Maybe the conversion utility broke something in your project. You could also try creating a new project and copying over all the source files as well.

Jonathan
A: 

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

Tim Jarvis
A: 

I'm guessing the parameter to the method you are passing the lambda into accepts a Delegate as a parameter?

If this is true then you will need to cast the lambda as a specific type of delegate. This is sort of confusing but what you need to know is that a lambda can't always be inferred correctly so you need to cast it or change the method signature to accepts specific types of delegates.

try this:

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

Also you could try making a few overloads for Initialize to accept specific types of delegates (such as Action).

If your method does accept a specific type of delegate type than you can ignore this answer :)

justin.m.chase
For this case, using Initialize((T x) => { ... }); would be clearer. Also, the compiler error message would be different.
configurator
+7  A: 

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:

<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, ensure that the correct folder is set as an application, and that it is using ASP.NET v2.blah (not v1.1.blah).

Marc Gravell
Thanks! I had a feeling the problem was with the compiler options. I poked around Visual Studio and didn't really see anything useful.
Christopher Bright
+1 Exactly what I was looking for
Paul Suart