10

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

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

2
  • 4
    Which C# version are you using? Commented May 24, 2011 at 12:41
  • Microsoft Visual C# 2008, Microsoft Visual Studio 2008, .NET 3.5 SP1 Commented May 24, 2011 at 12:52

9 Answers 9

19

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

Sign up to request clarification or add additional context in comments.

4 Comments

I don't see System.Core as an option in Right-click References > Add Reference.
Had to change Project > Properties > Application > Framework from 2.0 to 3.5
In that case you're probably writing a Net 2.0 or, even worse, 1.0-1 library. System.Core, as I say in my answer is 3.5 and above
@JackN - I just updated my answer to say that exact same thing :)
5

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

1 Comment

@takrl: Rather vote for @Andras Zoltan. He provided the most complex answer first.
5

Try to add System.Core assembly to your project

Comments

4

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

Comments

4

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

Comments

3

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

Comments

3

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.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.