LINQ in Action - LINQ Book & News

LINQ support on .NET 2.0

We have a forum for LINQ in Action, where current and future readers can post questions related to the book or to LINQ in general. Here is one question we received recently:

The first chapter states "This means that the applications you’ll build using LINQ can run in a “bare” .NET 2.0 runtime!" ....
Is this true? Or will it require our runtimes to install .NET 3.0 ... or .NET 3.5?

That's right, that's what I wrote in the book. But I hadn't really tried to see what can be achieved. So, here is a small test I did with Visual Studio 2008 Beta 2 and that you can reproduce: 

  1. Create a new console application
  2. Keep only System and System.Core as referenced assemblies
  3. Set Copy Local to true for System.Core, because it does not exist in .NET 2.0
  4. Use a LINQ query in the Main method. For example the one below.
  5. Build
  6. Copy all the bin output to a machine where only .NET 2.0 is installed
  7. Run

It should run without any problem. At least it did for me. The sample .NET 3.5 LINQ application I created did run on a machine where neither .NET 3.0 nor .NET 3.5 have been installed ever.

Warning: This may not work in all cases. I know that .NET 2.0 SP1 is installed with .NET 3.5. It may be required under certain circumstances, but I don't know which. In my case, I didn't use .NET 2.0 SP1, and to the best of my knowledge there is not separate installation for it yet anyway.

Update: As Bobby Diaz points out in a comment. .NET 2.0 SP1 is actually required if you want to use LINQ to SQL on .NET 2.0 because it contains an updated version of System.dll! See this forum post for more information.

The sample code I used:

class Program
{
  static void Main(string[] args)
  {
    var processes =
      from process in System.Diagnostics.Process.GetProcesses()
      where process.ProcessName.StartsWith("s")
      select new {process.Id, Name = process.ProcessName};

    foreach (var process in processes)
      Console.WriteLine(process);
  }
}
Published Wednesday, September 5, 2007 6:08 PM by Fabrice Marguerie

Comments

 

Bobby Diaz said:

.NET 2.0 SP1 is required if you want to use LINQ to SQL due to its use of the IPropertyChanging interface.

I found this out the hard way!

September 5, 2007 10:08 AM
 

Fabrice Marguerie said:

Thank you for the info, Bobby.

September 5, 2007 10:19 AM
 

Vikram said:

will it work on VS 2005 anyway?

September 5, 2007 9:37 PM
 

Fabrice said:

You can't compile LINQ code with VS 2005, however you can use an assembly created with VS 2008 or .NET 3.5 in VS 2005.

September 6, 2007 2:17 AM
 

Israel A said:

September 7, 2007 1:23 PM
 

O mundo é cada dia mais .NET... said:

Amigos, vocês não leram errado não. Descubra como é possível fazer rodar uma aplicação que utiliza os...

September 12, 2007 6:15 AM
 

Scott Hanselman's Computer Zen said:

July 8, 2008 12:55 PM
 

Dan said:

It doesn't work for LINQ to XML does it? Just been trying.

January 26, 2009 2:19 PM
 

Fabrice Marguerie said:

I've never tried with LINQ to XML. Did you try with a reference to System.Xml.Linq.dll?

January 26, 2009 4:37 PM
New Comments to this post are disabled