Fabrice's weblog

Tools and Source

News

My .NET Toolbox
An error occured. See the script errors signaled by your web browser.
No tools selected yet
.NET tools by SharpToolbox.com

Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

Tuneo

ASP.NET Hosting transatlantys

Contact

Me

Others

Selected content

Archives

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);
  }
}

Cross-posted from http://linqinaction.net

Comments

Vikram said:

wow that can be a very very good news. will try it today

# September 5, 2007 2:15 PM

Jay R. Wren said:

I don't believe it.  :)

The linq expression gets compiled to use extension methods on IEnumerabe<> from the System.Linq.Queryable static class. This is in the 3.5 System.Core assembly.

So in the above expression you have where & select which are ultimately calls to Queryable's Where<> and Select<>. So where is this code? Is it part of the System.dll in SP1?  

# September 13, 2007 1:49 PM

Fabrice Marguerie said:

> I don't believe it.  :)

Give it a try then :-)

> The linq expression gets compiled to use extension methods on IEnumerabe<> from the System.Linq.Queryable static class.

False. It's System.Linq.Enumerable.

> This is in the 3.5 System.Core assembly.

True.

> So in the above expression you have where & select which are ultimately calls to Queryable's Where<> and Select<>. So where is this code? Is it part of the System.dll in SP1?

As you write, this is in System.Core.dll. This is why, in step 3, I request a copy of this assembly to be included with the .exe file.

# September 13, 2007 5:31 PM

Jay R. Wren said:

I'm so sorry.

I missed step 3 where it says "mark System.Core as Copy Local".

I did not read the fine post (rtfp).

# September 14, 2007 1:51 PM

Fabrice Marguerie said:

:-)

# September 14, 2007 4:47 PM

Xcalibur said:

Are there any legal issues with redistributing the .NET 3.5 System.Core dll with your application? (eg - a commercial application)

# June 8, 2008 10:54 AM

Jeff Brown said:

@Xcalibur

I'm also very interested in the answer to the question about whether it is legal to redistribute System.Core.dll.

# June 27, 2008 2:30 AM

Denis Mazourick said:

This is interesting for me as well - Are there any legal issues with redistributing the .NET 3.5 System.Core dll with your application?

# August 1, 2008 8:38 AM

Fabrice Marguerie said:

It's not easy to find information on whether you can redistribute System.Core.dll or not.

A source of information is Scott Hanselman's blog: "You must not redistribute System.Core.dll to a 3rd party. You mustn't bundle it or ship it with your application."

See www.hanselman.com/.../DeployingASPNETMVCOnASPNET20.aspx

The key here may be "3rd party". My understanding is that you can do that inside your company but not outside.

But this is not really clear. It would be better to know the official policy.

# August 1, 2008 9:02 AM

Sergio Samayoa said:

Mmmm...

My current web hosting has only ASP.NET 2.0 and I really want to go for linq.

But it seems that I cant...

# August 21, 2008 2:45 PM

Gabriel Brancolini said:

Why this works? Easy, the .net framework 2.0, 3.0 and 3.5 works on the same clr (2.0), so every assembly can be reference from 2.0 to upper. It wouldnt work with .net 4.0 because it use another clr with things such as dynamic.

Congats for this article! keep in mind that Ms sais that it is not remocomended because any assembly could be recompiled in future versions and it wouldnt be very good thing.

At last, remember that you can do the same with Foundations libraries and any other with 3.5.

Gabriel Brancolini from Argentina

# October 27, 2011 1:06 PM