简体   繁体   English

Visual Studio无法识别System.Linq

[英]Visual Studio Does not recognize System.Linq

I created this program and C# and it worked correctly a few weeks ago. 我创建了这个程序和C#,几周前它运行正常。 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. 我将它添加到我正在进行的项目中的全新C#类中。 Visual Studio didn't recognize the assembly references that say "not found" in the comments. Visual Studio无法识别注释中“未找到”的程序集引用。

This is just bizarre since they were found in the previous program. 这是奇怪的,因为它们是在之前的程序中找到的。 Does anyone know why Visual Studio can't find these assembly references. 有谁知道为什么Visual Studio找不到这些程序集引用。

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;

An educated guess: It's probably the .NET framework target version of the new project. 一个有根据的猜测:它可能是新项目的.NET框架目标版本。

System.Linq was introduced on .NET Framework 3.5. System.Linq是在.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 它可能是3.5之前的目标框架

You need to add refrence to system.Core. 您需要向system.Core添加refrence。

在此输入图像描述

  • Step 1) Go to your Project Solution Explorer and Select References 步骤1)转到Project Solution Explorer并选择References
  • Step 2) Right click it on References and Select Add Reference... a form will appear 步骤2)右键单击引用并选择添加引用...将出现一个表单
  • Step 3) Search linq on Search bar 步骤3)在搜索栏上搜索linq
  • Step 4) Now Select/tick the System.XML.Linq checkbox 步骤4)现在选中/勾选System.XML.Linq复选框
  • Step 5) Click Ok 步骤5)单击“ 确定”

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. 您需要在解决方案资源管理器中右键单击解决方案,并在“项目属性”中添加对System.Xml.Linq和/或System.Linq的引用。

This has hit me several times - I see it a lot with System.Configuration as well. 这已经让我好几次了 - 我在System.Configuration中也看到了很多。 (For some reason those two references seem to be particularly picky) (出于某种原因,这两个引用似乎特别挑剔)

If your file is in App_Code folder, try moving it to another folder. 如果您的文件位于App_Code文件夹中,请尝试将其移动到另一个文件夹。 For me its solved the problem. 对我来说,它解决了这个问题。

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 PROJECT ==>添加引用==>浏览==> 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 你可以在Os System Drive上使用Windows搜索找到System.core.dll

I had a similar issue. 我有一个类似的问题。 I upgraded my asp.net project to .NET Framework 4.5.x and it worked. 我将我的asp.net项目升级到.NET Framework 4.5.x并且它工作正常。 I did tried 4.5.1 first and then later 4.5.0 and both seem to be helping. 我先尝试过4.5.1然后再尝试4.5.0,两者似乎都在帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM