If you receive an error in your .aspx page that looks something like:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name ‘Linq’ does not exist in the namespace ‘System.Data’ (are you missing an assembly reference?)
You may be able to resolve the error simply by adding an assembly reference to your Web.config file.
In our example error you will notice that the compiler is having problems finding the “Linq” namespace within the “System.Data” namespace. It is strange to me that the Linq namespace cannot be found since the reference has been added to the web applications “References”. Regardless, to explicitly tell the compiler to include the Linq namespace add the following attribute to the Web.config file.
<configuration> <system.web> <compilation debug="true" targetFramework="4.0"> <assemblies> <add assembly="System.Data.Linq, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </assemblies> </compilation> </system.web> </configuration>
By adding the Linq assembly to the system.web configuration’s assemblies, the error noted at the top of this post was resolved. Why the compiler couldn’t/didn’t find the Linq assembly without explicitly defining it in the web.config (i.e. it’s only defined in the web application’s “References” list) baffles me. If you know the answer to this puzzler, let me know :)
On a related note, if you are adding a Linq assembly that has a PublicKeyToken different than “b77a5c561934e089”, but you don’t what what your PublicKeyToken is, read “How to Determine the Public Key Token of an Assembly“.