简体   繁体   中英

C# using System.Linq error

Why might "using System.Linq" cause the following error?

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

Reference System.Core

And then there are others that merge this namespace too - but that's the primary one on.Net 3.5 and above .

If you're project is currently.Net 2.0, say, and you're using the right version of VS (2005 and above) - you can simply right-click on the proejct properties; and change the 'Target Framework Version' to 3.5. System.Core will then become available.

If you don't see that in the options - then I guess you're using an older VS

The most probable reason is that you are using wrong version of .NET Framework.

Try to add System.Core assembly to your project

You'll get this error if you don't have "System.Core.dll" referenced (the assembly which contains the core LINQ APIs).

System.Linq is available in.Net 3.5 and above version.

Maybe you're targeting an older framework, Linq came in with 3.5 IIRC.

You are using lower version of .NET Framework than 3.5 to compile the source code or you don't have added the System.Core assembly to your project.

Manually type using System.Linq in the starting of the project, you will not be able to find this namespace in add reference dialogue box. If you are still getting error then try to Add Reference System.Core . If you are getting an error that it has been already referred then you can unload your project and then edit your csproject file, manually copy reference to System tag and paste and change the name to System.Core and reload the project.

In my case the only thing that worked was:

Adding a new Razor item (eg MVC 5 View Page)

添加新的剃刀项目

That automatically pulls in some NuGet packages

已安装的 NuGet 包

The package that makes System.Linq available to Razor Views IntelliSense seems to be Microsoft.AspNet.WebPages .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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