tags:

views:

156

answers:

2

I added a reference to the System.Core assembly. The web.config now has:

<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

The IIS is set to use ASP.NET version 2.0.50727

Though intellisense shows the extension methods, the compiler does not understand the linq syntax. I can use Linq in other class libraries in the solution.

How do I fix this?

**EDIT: I have the following already in the web.config

<system.web>
 <compilation
    <assemblies>
    <!-- references here //-->
    </assemblies>
      <compilers>
        <compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs" compilerOptions="/d:DEBUG;TRACE" />
      </compilers>
    </compilation>
</system.web>

I don't have the <system.codedom> node. This is a project that has been migrated from 1.x to 2.x to 3.5. Do I remove the <compilers> from the and add it to <system.codedom> ?

Please note that I want to do minimal change necessary to get this to work as this is a large scale Enterprise project (and I dont want to mess with the web.config too much) **

+4  A: 

Just adding the assembly creates a reference, but you have to specify which version of the compiler you are using.

You need to update the <system.codedom> element in the web.config file:

<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=b77a5c561934e089">
      <providerOption name="CompilerVersion" value="v3.5" />
      <providerOption name="WarnAsError" value="false" />
    </compiler>
  </compilers>
</system.codedom>

The important part you have to make sure is in the <compiler> element is this child element:

<providerOption name="CompilerVersion" value="v3.5" />

This makes sure that you are using v3.5 of the C# compiler.

The <system.codedom> element is a child of the <configuration> element, as per the documentation:

http://msdn.microsoft.com/en-us/library/k6bttwes.aspx

casperOne
Thanks, Will try it out. Curious to know why compiler does not complain about linq queries in the class libraries in other projects in the solution
DotnetDude
@DotnetDude: Because those are class libraries and the project file is set to use the C# compiler. With ASP.NET, you have to use the compiler on the server, not the one on your dev/build machine. Because of SxS, you have different compilers to use.
casperOne
Can you pls take a look at my edit? Thanks
DotnetDude
@DotnetDude: See my edit with the link.
casperOne
A: 

Using a Web Application Project rather than a Web Site will not give this issue (for reference) as it builds the code into a DLL.

ck