Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / CLR

CLR Versions

5.00/5 (3 votes)
29 Aug 2012CPOL3 min read 23.2K  
Lets learn different CLR versions which exist and did we miss one between v2.0 and v4.0?

Today, I want to talk about different CLR versions which exist and our understanding about them. Let’s build a small application and build it against different versions of .Net framework. We will use vanilla source code to output "Hello World" and the underlying (CLR) framework version used.

Source Code:

C#
using System;

public class HelloApp
{
    static public void Main()
    {
        Console.WriteLine("Hello World!!");
        Console.WriteLine();
        Console.WriteLine(string.Format("Framework version used : {0}", Environment.Version));

        Console.ReadLine();
    }
}

Let’s build the application against different versions of .Net Framework (using Visual Studio).

In order to compile the application you need to open Visual Studio 20XX Command Prompt and use the following command:

csc HelloApp.cs 

It will generate HelloApp.exe and you can check the metadata of the generated assembly by using following command:

ildasm HelloApp.exe

Now let’s check output of the above program with respect to different versions of .Net Framework and the metadata changes.

 

Visual Studio 2003 (.Net Framework 1.1)

Compiling the application and executing it from VS 2003 command prompt produces the following output:

VS2003 CLR 1.1 Execution

As we can see, (and as expected) it is targeting CLR v1.1. Let’s check the metadata of the generated assembly:

CLR 1.1 Assembly Metadata

It shows the Metadata version and the version of mscorlib being targeted. We can see it is targeting CLR v1.1, which is what one would expect.

 

Visual Studio 2005 (.Net Framework 2.0)

Compiling the application and executing it from VS 2005 command prompt produces the following output:

VS2005 CLR 2.0 Execution

As we can see, (and as expected) it is targeting CLR v2.0. Let’s check the metadata of the generated assembly:

CLR 2.0 Assembly Metadata

We can see it is targeting CLR v2.0, which is what one would expect.

Visual Studio 2008 (.Net Framework 3.0/3.5)

Compiling the application and executing it from VS 2008 command prompt produces the following output:

VS2008 CLR 2.0 Execution

Surprise!! It is targeting CLR v2.0, something which I did not expect. Let’s check the metadata of the generated assembly:

CLR 2.0 Assembly Metadata for VS2008

We can see it is targeting CLR v2.0, which confirms the reason for the above output. Why would an application compiled using Visual Studio 2008 (which was using .Net Framework 3.5) target .Net Framework 2.0? Before answering this question, let’s see the output with Visual Studio 2010.

Visual Studio 2010 (.Net Framework 4.0)

Compiling the application and executing it from VS 2010 command prompt produces the following output:

As we can see, (and as expected) it is targeting CLR v4.0. Let’s check the metadata of the generated assembly:

We can see it is targeting CLR v4.0, which is what one would expect.

So, we saw the application targeting CLR v1.1, 2.0, and v4.0 but, where did CLR v3.0/3.5 go? In fact, CLR v3.0/v3.5 never existed. In reality, .Net Framework 3.0 release contained additional set of libraries such as WCF, WF, and WPF which were all built upon existing CLR v2.0. The underlying CLR was not changed at all as part of .Net Framework v3.0 release. None of the core libraries were changed and hence the CLR version remained same. CLR version has now changed with .Net Framework v4.0 release as there are substantial changes to Base Class Library (BCL) in CLR v4.0. Basically, CLR skipped version from v2.0 to v4.0. There was no CLR v3.0 or v3.5.

In my next post, we will see applications compatibility between CLR versions i.e. how applications targeting a particular version of CLR work with another version (i.e. forward and backward compatibility)

Vande Mataram!

(A salute to motherland)

P.S. In addition to blogging, I use Twitter to share tips, links, etc. My Twitter handle is: @girishjjain

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)