The other day while working on a SharePoint project, we needed a simple utility to show us the current build and version numbers of deployed assemblies. Rather than going through the hassle of creating a custom web-part or compiled assembly, I decide to opt for a simple ASPX page with inline code.
The approach worked well. I had IntelliSense and I wasn’t limited to any language features until I added a few simple Linq statements. I then ran into this fun error:
error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) at System.Web.Compilation.AssemblyBuilder.Compile()
Despite the fact that .NET 3.5 was installed and other compiled assemblies worked fine on this machine, the ASP.NET process was having problems compiling the Linq features on its own. It just needed some additional guidance on where to locate those assemblies…
First, the compiler needs a hint on how to resolve the Linq assembly, located in System.Core:
<compilation batch="false" debug="true"> <assemblies> <!-- add –> <add assembly="System.Core, Version=126.96.36.199, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> </assemblies> </compilation>
Then, the module that compiles our code needs a hint to build using 3.5:
<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5" /> <providerOption name="WarnAsError" value="false" /> </compiler> </compilers> </system.codedom>