The type or namespace name 'Linq' does not exist in the namespace 'System'

79,104

Solution 1

I had an issue with System.Linq not being recognized. The way I solved it was to change the targeted framework of my website from 4.0 to to 3.5 and then switch back to the original targeted framework (in my case 4.0)

  1. Hit Shift+F4 or right click at the project level and select Property Pages in Visual Studio. (Alt+Enter or right click at the project level and select Properties in VS2017.)
  2. Change the Target Framework from .Net Framework 4 to .Net Framework 3.5
  3. Confirm with OK
  4. Repeat this process in reverse so, again hit Shift+F4
  5. Change it back from .Net Framework 3.5 to .Net Framework 4

Hope this helps

Solution 2

Try to Unload and then reload the concerned project. That will do it.

Solution 3

Put this piece of code in the Configuration file (Web.config) and test it.

<compilation debug="false">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>

Solution 4

Visual Studio 2015 References -> Add Reference -> Assemblies -> select System.Data.Linq

Solution 5

Try this one. Maybe targetFramework="4.0" will work. Worked for me.

<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>

Share:
79,104

Related videos on Youtube

javad
Author by

javad

Updated on September 05, 2020

Comments

  • javad
    javad almost 4 years

    When I want to use button to write code in C# it doesn't go to the ".cs" file to write C# code. When I check the project source, I found this error:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    

    Severity Code Description Project File Line Error CS0234 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) Golestani C:\Users\javad\Documents\Golestani\Login.aspx.cs 3

    Image

    • javad
      javad about 8 years
      What Do You Mean??
    • Hamed
      Hamed about 8 years
      Right click your project -> Add Reference -> select Framework tab -> select System.Core
    • AmirHossein Rezaei
      AmirHossein Rezaei almost 6 years
      Go to project -> References -> Add Reference -> -> Assemblies -> Search for "System.Xml.Linq" and check it.
  • Malcolm Anderson
    Malcolm Anderson about 7 years
    If Shift+F4 doesn't work, just right click at the project level and select "Property Pages"
  • EricImhauser
    EricImhauser over 5 years
    That did work for me after hours of research. Thanks
  • user2163234
    user2163234 over 5 years
    VS is nice when it works, but its some ungodly Frankenstein collection of stuff and things go to hell frequently and are a nightmare figure out. It's frustrating when you decide to reinstall windows just to get VS to work again. Teach me to try to use it for R and Python and still expect C# to work too.
  • Aron Boyette
    Aron Boyette over 5 years
    I had success with this change, although I only needed to do System.Core. And for those who haven't memorized the the Web.config XML schema, the <compilation> element goes under <system.web>. @Hamed, I urge you to change your answer to include <system.web> and to fix the syntax highlighting.
  • blind Skwirl
    blind Skwirl almost 5 years
    yup, just closing and reopening VS2017 did it for me. Happens often for various issues.
  • yu yang Jian
    yu yang Jian over 4 years
    This action may change the content of web.config, suggest to check what content is modify after change, to ensure that no function is thus disabled.
  • Marco Aurelio Fernandez Reyes
    Marco Aurelio Fernandez Reyes about 3 years
    In my case (changing from Framework 2.0 to Framework 3.5) fixed the problem. Thank you.
  • Rajesh Thampi
    Rajesh Thampi over 2 years
    Worked on Windows 2008 R2 for an age old intranet website. Thank you.
  • wallef
    wallef over 2 years
    This worked for me in VS 2022