7

I created this program and C# and it worked correctly a few weeks ago. Now, I copied all of this code to a another project I am working on. I added it to a brand new C# Class inside of the project I am working on. Visual Studio didn't recognize the assembly references that say "not found" in the comments.

This is just bizarre since they were found in the previous program. Does anyone know why Visual Studio can't find these assembly references.

using System;

using System.Collections.Generic;

using System.Linq;    //not found
using System.Text;
using XML_Creator;     //not found
using System.Xml.Linq; //not found
using System.IO;
6
  • 1
    Have the references been added to the project?
    – Sneftel
    Commented Jul 9, 2014 at 17:17
  • Do you have System.Xml.Linq.dll referenced in your new project?
    – Nathan A
    Commented Jul 9, 2014 at 17:17
  • Which version of the .NET framework are you using?
    – fabricio
    Commented Jul 9, 2014 at 17:17
  • I am using framework 4.0
    – tennis779
    Commented Jul 9, 2014 at 17:18
  • @user3670048 The question would be: which target version of the .NET framework is the project using? Commented Jul 9, 2014 at 17:21

7 Answers 7

19

An educated guess: It's probably the .NET framework target version of the new project.

System.Linq was introduced on .NET Framework 3.5.

Go to Project -> Properties -> Application and check the Target Framework property. It's probably a target framework prior to 3.5

1
  • 3
    This might not actually be the case. My target framework in the project properties was showing 4.0, but I am working in a Web project and the Web.config didn't have a "targetFramework" attribute on the <compilation> tag. Adding 'targetFramework="4.0"', closing the project, and reopening it fixed it for me. You can also toggle the properties to 3.5 and back to 4.0, but it takes more time.
    – Daved
    Commented Nov 5, 2015 at 18:41
18

You need to add refrence to system.Core.

enter image description here

5
  • 3
    Why System.Core.dll rather than System.Linq.dll?
    – xr280xr
    Commented Jul 22, 2019 at 16:12
  • @xr280xr If you are still curious, it's because the System.Linq namespace definition is actually in the System.Core assembly (in System.Core.dll).
    – Joey
    Commented Jan 6, 2020 at 16:24
  • 2
    In VS2019 (.NET 4.7.X), this reference cannot be (explicitly) added, it fails with "A reference to 'System.Core' could not be added. This component is already automatically referenced by the build system"
    – LCC
    Commented Apr 17, 2020 at 11:27
  • Completely new Clean MVC project .net 4.8, gives me this error too. I tried just about everything in here. Coincidentally; if I make a new MVC project in VB, I dont get missing Linq error. Go figure
    – Christian
    Commented Mar 10, 2021 at 22:19
  • There are tons of reasons, why one has to stick to .NET framework, instead of Core, typically it's out of his/her hands. In addition to that, you cannot change a .NET framework to Core without quite some work. So even though this might work, it's not very helpful, IMHO. Commented Dec 16, 2021 at 6:49
10
  • Step 1) Go to your Project Solution Explorer and Select References
  • Step 2) Right click it on References and Select Add Reference... a form will appear
  • Step 3) Search linq on Search bar
  • Step 4) Now Select/tick the System.XML.Linq checkbox
  • Step 5) Click Ok
3
  • Somebody already mentioned this...but I when I do this there is no search bar...and I cannot find System.XML.linq
    – tennis779
    Commented Jul 9, 2014 at 18:13
  • 7
    You need a reference to System.Core for Linq to work in .Net framework 4
    – Durre
    Commented Jul 9, 2014 at 18:27
  • You just Saved my day
    – nkigen
    Commented Apr 2, 2017 at 12:19
4

If your file is in App_Code folder, try moving it to another folder. For me its solved the problem.

0
3

You need to right click on the solution in Solution Explorer and add a reference to System.Xml.Linq and/or System.Linq in Project Properties.

This has hit me several times - I see it a lot with System.Configuration as well. (For some reason those two references seem to be particularly picky)

3
  • Well now I am running into the problem that System.Linq and System.XML.Linq isn't in the browser ... :(
    – tennis779
    Commented Jul 9, 2014 at 17:29
  • 1
    Please note that System.Linq namespace is in the System.Core assembly, not System.Xml.Linq Commented Jul 9, 2014 at 17:31
  • This did work, I thought I was using the 4.0 framework, when it was set to 2.0... so this didn't show System.XML.Linq
    – tennis779
    Commented Jul 9, 2014 at 19:08
1

For me I tried this and worked:

PROJECT==>Add Reference ==> Browse ==> C:\Windows\winsxs\x86_netfx35linq-system.core_31bf3856ad364e35_6.1.7601.17514_none_6161fc35ed136622\System.core.dll

Or

you can simply find the System.core.dll using windows search on Os System Drive

0

I had a similar issue. I upgraded my asp.net project to .NET Framework 4.5.x and it worked. I did tried 4.5.1 first and then later 4.5.0 and both seem to be helping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.