The type or namespace name ‘Linq’ does not exist in the namespace ‘System.Data’

If you receive an error in your .aspx page that looks something like:

Compilation Error

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.

     <compilation debug="true" targetFramework="4.0">
        <add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

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


4 thoughts on “The type or namespace name ‘Linq’ does not exist in the namespace ‘System.Data’

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s