Thursday, June 13, 2013

Linq with .Net 2.0

Today I came to read out an interesting article, so thought of sharing the same with you all.

There are some "Hacks" that involve using a System.Core.dll from the 3.5 Framework to make it run with .net 2.0

A small test with Visual Studio 2008 Beta 2 to 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, like the one i mentioned below.
  5. Build
  6. Copy all the bin output to a machine where only .NET 2.0 is installed
  7. Run


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

 .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!


Why this works? 
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 would not work with .net 4.0 because it use another clr with things such as dynamic.
Also, remember that you can do the same with Foundations libraries and any other with 3.5.


NOTE: Redistributing System.Core.dll is a violation of Microsoft's license

No comments:

Post a Comment