Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Changing SharePoint Default ASP.NET compiler to use ASP.NET 3.5

Overview

While SharePoint 2010 supports .NET 3.5, it uses the .NET 2.0 compiler by default for ASP.NET pages.  If you write any UserControls or consume any DLLs in your hosted ASPX pages that utilizes .NET 3.5 features such as the var keyword, extension methods, and LINQ, you’ll get compilation error messages when attempting to access those pages.

To resolve this issue, you can edit the web.config in your site collection’s virtual directory (Usually under \inetpub\wwwroot\wss\virtualdirectories\<site>).  Add the following snippet under the configuration element:

 

<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>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Also, look under the Assemblies section and make sure you have the following entries:

   1: <add assembly="System.Web.Extensions, Version=3.5.0.0,Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

   2: <add assembly="System.Xml.Linq, Version=3.5.0.0,Culture=neutral, PublicKeyToken=B77A5C561934E089" />

   3: <add assembly="Microsoft.SharePoint, Version=14.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

   4: <add assembly="System.Web.Extensions, Version=3.5.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

   5: <add assembly="Microsoft.Web.CommandUI, Version=14.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

   6: <add assembly="Microsoft.SharePoint.Search, Version=14.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

   7: <add assembly="Microsoft.Office.Access.Server.UI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

   8: <add assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

 

Note: You can also add other .NET 3.5 assemblies here as needed.

1 Comment. Leave new

[…] original post here: Changing SharePoint Default ASP.NET compiler to use ASP.NET 3.5 ← SharePoint Interview Questions from Stack Overflow […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

\\\