none
Difficulty using System.Data.Linq in VS 2008 (CS0234 error)

    Question

  • Ok first of thank  you in advance for any advice or suggestions...

    I am currently working on a small web application and decided to use LINQ to serve as as the means from which i will access my SQL Server DB. I created the db tables and structure from within VS and then added a new 'linq to SQL class' in my wem application project. I imported all tables in the designer view of my LINQ to SQL class and saved to generate the underlying DataContext code. I then moved on to create a data access layer class (DALProfile) to manage any requests to the db through LINQ. the class imports the following namespaces:

    Code Snippet



    using System.Data.Linq;
    using System;
    using System.Collections;
    using System.Xml.Linq;
    using System.ComponentModel;
    using System.Linq;
    using System.Data;
    using requestSystem.App_Code.BusinessObject;
    using requestSystem.App_Code.BusinessObject.Collections


    and i access the LINQtoSQL class through an instance of the dataContext like this:

    Code Snippet

    namespace requestSystem.App_Code.DataAccess
    {
        public static class ProfileDAL
        {


            private static DBLinqDataContext objDataContext = new DBLinqDataContext();

            

            ...



    now when i build the application from within VS 2008 everything compiles without an error... but when i run it i get the following error:

    Compiler Error Message: CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

    Source Error:

    Line 1:  using System.Data.Linq;

    and i triple checked my project references... both System.Core and System.Data.Linq appear....

    funny thing is i get a compile error for the DAL class but not the generated LINQtoSQL class code.... and ia lso ensured my project was set to use the 3.5 framework.

    and as an FYI my DAL classes are in a subfolder called "DataAccess"

    any help is greatly appreciated

    Thanks!!


    Thursday, April 03, 2008 5:46 PM

Answers

  • Hi Nalverio,

     

    Not sure if this applies to your case by I ran into this problem.

     

    Check your web.config file - do you see a reference to System.Data.Linq within the compilation/assemblies section?

     

    Depending on how you originally created your project the web.config file may not get updated when adding references to your project. It would appear that "File/New/Project/asp.net web application" behaves differently to "File/New/Website"  as under the latter when adding a reference to System.Data.Linq.dll this also automatically updates the web.config file whereas under the former it doesn't!

     

    To fix this add to the web.config under the section mentioned above the following:

     

    <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=xxxxx"/>

     

    where the public key token is the same as that used to sign System.Data.DataSetExtensions

     

    Hope this helps.

     

     

     

     

    Wednesday, April 16, 2008 4:14 PM
  • Thanks for the suggestion... I actually found this after digging a little deeper. My web.config did not have the assembly line for the Data.Linq assembly.... very frustrating that visual studio didn't do this on.

     

    Either way that was the problem Smile Thanks.

     

     

     

    Wednesday, April 16, 2008 4:23 PM

All replies

  • Hi Nalverio,

     

    Not sure if this applies to your case by I ran into this problem.

     

    Check your web.config file - do you see a reference to System.Data.Linq within the compilation/assemblies section?

     

    Depending on how you originally created your project the web.config file may not get updated when adding references to your project. It would appear that "File/New/Project/asp.net web application" behaves differently to "File/New/Website"  as under the latter when adding a reference to System.Data.Linq.dll this also automatically updates the web.config file whereas under the former it doesn't!

     

    To fix this add to the web.config under the section mentioned above the following:

     

    <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=xxxxx"/>

     

    where the public key token is the same as that used to sign System.Data.DataSetExtensions

     

    Hope this helps.

     

     

     

     

    Wednesday, April 16, 2008 4:14 PM
  • Thanks for the suggestion... I actually found this after digging a little deeper. My web.config did not have the assembly line for the Data.Linq assembly.... very frustrating that visual studio didn't do this on.

     

    Either way that was the problem Smile Thanks.

     

     

     

    Wednesday, April 16, 2008 4:23 PM
  • I was having this problem as well and adding the assembly declaration to the web.config worked for me too.  I was just wondering if there's a any way this assembly can be added automatically when you create a new web application project, or are we stuck with having to type it manually each and every time?
    Tuesday, October 07, 2008 2:37 PM
  •  

    as far as i know there isnt... it doesnt seem to be consistent but i haven't been able to pin down the scenario's that cause VS 2008 to neglect the assembly entry. Let me know if you find anything else out though.
    Tuesday, October 07, 2008 2:45 PM
  • THANK YOU! Your suggestion worked for me also.
    Friday, October 17, 2008 3:50 PM
  • Also experienced this problem. I removed everything from "references" and compiled and then slowly added the references it required from scratch.

    After that it worked. Some somehow, the references in my project got messed up.

     

     

    Thursday, August 05, 2010 1:33 PM
  • This has worked for me

    Right-click on the project's name in solution explorer => Add reference =>.NET Tab=> select System.Data.Linq => Press OK

    Wednesday, March 07, 2012 6:57 AM