jacknad
jacknad

Reputation: 13739

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'

Upvotes: 10

Views: 29136

Answers (9)

wc.matteo
wc.matteo

Reputation: 41

In my case the only thing that worked was:

Adding a new Razor item (e.g. MVC 5 View Page)

Add new Razor item

That automatically pulls in some NuGet packages

installed NuGet packages

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

Upvotes: 0

sarawgeek
sarawgeek

Reputation: 689

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.

Upvotes: 0

Andras Zoltan
Andras Zoltan

Reputation: 42363

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

Upvotes: 19

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.

Upvotes: 3

FIre Panda
FIre Panda

Reputation: 6637

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

Upvotes: 4

Torbjørn
Torbjørn

Reputation: 6503

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

Upvotes: 4

Stecya
Stecya

Reputation: 23276

Try to add System.Core assembly to your project

Upvotes: 5

takrl
takrl

Reputation: 6482

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

Upvotes: 3

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364409

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

Upvotes: 5

Related Questions