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

  • Question

  • User-1330485181 posted

    Hi All,

    Summary of the problem I am having:

    I am building ASP.NET C# Web form using Visual Studio 2019 with Target framework 4.72,  but I found error like this below

    Error I am receiving:

    <

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

    Source Error:

    Line 12: namespace WebApplication1.App_Code
    Line 13: {
    Line 14: 	using System.Data.Linq;
    Line 15: 	using System.Data.Linq.Mapping;
    Line 16: 	using System.Data;


    Source File: D:\GL-Project\WebApplication1\WebApplication1\App_Code\DataClassesGL.designer.cs    Line: 14


    Show Detailed Compiler Output:

     

    Show Complete Compilation Source:




    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4075.0 >

    My code:

    <

    #pragma warning disable 1591
    //------------------------------------------------------------------------------
    // <auto-generated>
    // This code was generated by a tool.
    // Runtime Version:4.0.30319.42000
    //
    // Changes to this file may cause incorrect behavior and will be lost if
    // the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    namespace WebApplication1.App_Code
    {
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Data;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.ComponentModel;
    using System;


    public partial class DataClassesGLDataContext : System.Data.Linq.DataContext
    {

    private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

    #region Extensibility Method Definitions
    partial void OnCreated();
    #endregion

    public DataClassesGLDataContext(string connection) :
    base(connection, mappingSource)
    {
    OnCreated();
    }

    public DataClassesGLDataContext(System.Data.IDbConnection connection) :
    base(connection, mappingSource)
    {
    OnCreated();
    }

    public DataClassesGLDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
    base(connection, mappingSource)
    {
    OnCreated();
    }

    public DataClassesGLDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
    base(connection, mappingSource)
    {
    OnCreated();
    }
    }
    }
    #pragma warning restore 1591

    >

    Does the LinqToSQL still be able to used on dot Net Framework 4.72 or higher ? 

    Regards,

    Sentoso

    Friday, March 13, 2020 3:38 AM

Answers

  • User288213138 posted

    Hi Sentoso,

    I have followed your steps,  have changed 'Build Action"  to be set to "Compile" and Rebuild the project. I still got that error. I have tried to rebuild it several times, the error is still the same.

    It works in class and web form, but not in Linq to sql class. I suggest you put Linq to sql class elsewhere.

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 17, 2020 3:37 AM

All replies

  • User288213138 posted

    Hi Sentoso,

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

    This error should be that you did not add a reference to System.Data.Linq.

    Right click your project. Click Add Reference and search for System.Data.Linq and add the reference there and it should compile.

    Best regards,

    Sam

    Friday, March 13, 2020 9:37 AM
  • User-1330485181 posted

    Hi Samwu,

    I have already Add Reference System.Data.Linq , and still got that error message.

    Regards,

    Sentoso

    Friday, March 13, 2020 2:57 PM
  • User409696431 posted

    This happened to me for a project a week or so ago. The project had no errors, then suddenly was showing the same error you see.  A random sequence of closing the project, closing VS, rebooting my machine, opening VS and the project, rebuilding...  It took a few tries but eventually sanity was restored and the reference was recognized.  No idea what caused it.

    Saturday, March 14, 2020 12:28 AM
  • User-1330485181 posted

    I have remove the reference and add a reference to System.Data.Linq again, rebuild the project and had no error. It still does not work.

    I have tried create a new project for testing and add LINQ To SQL Classes, I got the same error, so I decided to use ADO.NET Entity Data Model.

    It seems LINQ To SQL Classes won't be supported if using .Net Framework 4.72 or higher.

    Saturday, March 14, 2020 4:12 AM
  • User409696431 posted

    "It seems LINQ To SQL Classes won't be supported if using .Net Framewo4.8rk 4.72 or higher."

    That's not true.  However there is an issue in VS with recognizing System.Data.Linq sometimes.   I set up a new project with framework 4.8 and got all the System.Data.Linq using's as "not a member of System.Data".  I followed advice from another site and changed the framework of the project to a different one (4.7.2) and they were recognized.  I changed the framework back to 4.8 and they remained recognized.

    So: try changing your framework and flipping it back.  This sounds akin to suggesting you dance widdershins under a full moon and have that fix it, but ... changing the framework back and forth actually works sometimes.

    Saturday, March 14, 2020 6:58 AM
  • User-1330485181 posted

    HI Kathy,

    I have tried to change the framework to the lower framework, rebuild the project many times & I still got the same error.

    Regards,

    Sentoso

    Saturday, March 14, 2020 8:15 AM
  • User288213138 posted

    Hi Sentoso,

    namespace WebApplication1.App_Code Line 13: { Line 14: using System.Data.Linq;

    The App_Code file contains source code for shared classes and business objects that you want to compile as part of your application. In a dynamically compiled Web site project, ASP.NET compiles the code in the App_Code folder on the initial request to your application. Items in this folder are then recompiled when any changes are detected.

    You can right click on the .cs file in the App_Code folder and check its properties. Make sure the "Build Action" is set to "Compile".

    After you change Build Action Property of the *.cs source file to Compile from Content, the namespace was resolved in other folder locations of the project.

    Best regards,

    Sam

    Monday, March 16, 2020 7:53 AM
  • User-1330485181 posted

    Hi Samwu,

    I have followed your steps,  have changed 'Build Action"  to be set to "Compile" and Rebuild the project. I still got that error. I have tried to rebuild it several times, the error is still the same.

    Regards,

    Sentoso

    Monday, March 16, 2020 11:40 AM
  • User288213138 posted

    Hi Sentoso,

    I have followed your steps,  have changed 'Build Action"  to be set to "Compile" and Rebuild the project. I still got that error. I have tried to rebuild it several times, the error is still the same.

    It works in class and web form, but not in Linq to sql class. I suggest you put Linq to sql class elsewhere.

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 17, 2020 3:37 AM
  • User-1330485181 posted

    Hi Samwu,

    Yes, you are right. It is working. Thank you very much.

    Regards,

    Sentoso

    Tuesday, March 17, 2020 5:44 AM