26

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

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
javad
  • 379
  • 2
  • 5
  • 9

5 Answers5

70

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

ElasticCode
  • 7,311
  • 2
  • 34
  • 45
DevCentral
  • 1,149
  • 11
  • 26
  • 8
    If Shift+F4 doesn't work, just right click at the project level and select "Property Pages" – Malcolm Anderson Apr 10 '17 at 20:17
  • 3
    That did work for me after hours of research. Thanks – EricImhauser Oct 24 '18 at 14:50
  • 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. – user2163234 Dec 14 '18 at 18:45
  • 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. – yu yang Jian Feb 29 '20 at 07:39
  • In my case (*changing from Framework 2.0 to Framework 3.5*) fixed the problem. Thank you. – Marco Aurelio Fernandez Reyes Mar 31 '21 at 21:25
31

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

minchiya
  • 603
  • 1
  • 7
  • 13
4

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>
Hamed
  • 590
  • 5
  • 16
  • 1
    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 element goes under . @Hamed, I urge you to change your answer to include and to fix the syntax highlighting. – Aron Boyette Feb 24 '19 at 22:10
  • Worked on Windows 2008 R2 for an age old intranet website. Thank you. – Rajesh Thampi Dec 16 '21 at 11:53
3

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

1

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>