HOW .NET PROGRAM EXECUTION WORKS
In order to understand .net program execution and benefits of it, it is better to take a look in to how pre .net execution worked before .net comes into play.
Before .net introduced programmers developed programs with many programming languages like VB6 ,C++ etc. Lets see how they worked before .net introduced.
When we developed an application with VB without .net framework we need to compile that application using a programming language specific compiler and then it will create a assembly. We called it also as machine code or native code which is the code machine can understand. According to the type of application we developed the assembly can be a dll or an exe. This machine code can be understand by the operating system which the compiler belongs to. That means if we compiled this application in a windows operating system it will runs successfully in a windows OS but not in a Linux OS.So this is the main problem we see when we program with pre .net and because of that reason those applications are not portable.
Lets see how .net addresses above problem
With .net framework you can use several programming languages like c#,VB,C++,J# and etc.That means if .net included relevant compiler for a programming language we can program with that programming language under .net. Lets see how .net programming execution works.
When we developed a program under .net framework as shows in the above diagram we can program with many programming languages which are supported by .net. When we compile the solution it will compile by different compilers which are relevant to the programming language and it will create assembly that could be .dll or .exe according to the type of program we created.But the important thing happens here is this assembly can’t be understand by the operating system as this compiling process does not generate machine /native code like we discussed in pre .net execution. Instead of that it will generate assembly which are formatted in to intermediate langue we called it as (IL). If we try to run this IL formatted assembly directly on top of the OS it will fail.
So then there should be some mechanism in between these assemblies with IL and operating system in order to make those assemblies can be run(understand by OS).The guy how is doing this job is called as CLR (Common Language Runtime).When .net installed on a machine it will install CLR on that machine that’s how it comes.
By CLR it will compile IL formatted assemblies in to machine code by the JIT compiler called as (Just In Time compiler) and those machine codes can be understand by the OS and the app will run.The advantage of JIT is it will generate machine code from IL according to the OS.Because of that we can make an application in windows OS and run it top on a Linux OS.