8

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;
tennis779
  • 338
  • 2
  • 6
  • 19

7 Answers7

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

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
  • 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 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 Nov 05 '15 at 18:41
18

You need to add refrence to system.Core.

enter image description here

Edwin O.
  • 4,998
  • 41
  • 44
  • 3
    Why System.Core.dll rather than System.Linq.dll? – xr280xr Jul 22 '19 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 Jan 06 '20 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 Apr 17 '20 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 Mar 10 '21 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. – Oak_3260548 Dec 16 '21 at 06: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
Durre
  • 109
  • 3
4

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

Ammar
  • 41
  • 2
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)

Tim
  • 4,051
  • 10
  • 36
  • 60
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

Shriram Panchal
  • 1,996
  • 1
  • 20
  • 23
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.

Amit
  • 559
  • 5
  • 8