views:

152

answers:

4

While trying to use linq in a .NET 2.0 winforms project I got:

Namespace or type specified in the Imports 'System.Linq' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases

In both the lines that reference the following namespaces:

System.Linq; System.Xml.Linq;

How could I get these namespaces to work on .NET 2.0 without referencing an external DLL or anything ?

+7  A: 

You can't. They were introduced in .NET 3.5.

I don't know of any implementations of LINQ to XML for .NET 2.0 (unless you use a Mono assembly - I assume Mono supports it). There's LINQBridge if you want LINQ to Objects in .NET 2.0, although of course that goes against your "no external libraries" requirement.

Jon Skeet
+1  A: 

Linq is not avaliable in .Net Framework 2.0 it was introduced in 3.5

Giorgi
+1  A: 

Supposably you can use LINQ in a .Net 2.0 app if you use the 3.0 compiler and include the Mono LINQ implementation. I have no idea how to do this, myself, and I'm pretty sure it means referencing an external DLL. However, .Net apps reference external DLLs all the time, so I wouldn't worry about that.

Update: There's something called LINQBridge which may provide what you need.

MusiGenesis
A: 

Reference System.Core (I suggest you find it in a .net 3.5 install)

Ric Tokyo