HOME RESOURCES PLACEMENTS CONTACT FEEDBACK SUBSCRIBE
QUICK LINKS .NET Articles
.NET Training Tutorial
HR Interview Questions
.NET Interview Questions
SQL Interview Questions
JAVA Interview Questions

Steps invloved in .NET application execution

Let's first understand how applications are executed before .NET came into existance. Figure1 below gives an overview of how a non .NET application is executed.

Figure 1

Steps involved in non .NET application execution in general
  • We have non .NET application source code developed in one of the high level languages on windows platform.High level languages cannot be understood by computers.
  • So the language compiler compiles the application and produces object code native to windows operating system. Systems can only understand object code.
  • The object code then runs on the operating system on which we have compiled. The same object code will not run on any other operating system other than the one on which the application is compiled. This is because object code of one operating system is different from the other.So the applications that we have developed prior to .NET are not platform independent. The applications are tied to the platform on which they are developed.
Before we understand .NET application execution, lets understand the 2 very important components of .NET.
  • FrameWork class library : The FrameWork class library contains all reusable classes, Interfaces and basic types for use within the applications we develop. The framework classes are present in different namespaces and physically packaged into assemblies.
  • Common Language runtime(CLR) : CLR is the runtime with in which .NET applications run. .NET applications do not run directly run on top of operating system, instead they run on CLR. The CLR is present on top of the operating system. CLR is a layer between operating system and our application which will convert the Intermediate language into native code that the underlying operating system can understand.
The way .NET applications are executed is a little different. Figure2 below shows how a .NET application is executed.
  • We develop .NET applications with any of the programming languages supported by .NET like C#,VB,J# or C++.
  • The application is then compiled with the compiler, which produces Iintermediate Language(IL) and physicall packaged into an assembly. Assemblies in .NET will have a .dll or .exe extension depending upon the application type. For example a web application compilation produces .dll where as a console or windows application compilation produces .exe in general. No matter in which language we have developed the application, after we compile the application Intermediate Language is produced.
  • The assembly that is produced as a result of compilation of .NET application, then runs on CLR. CLR is a layer between operating system and our application. CLR internally hosts a JIT(Just In Time) compiler, which will convert Intermediate Language into object code that the Operating system can understand.
  • When we close the application, the object code is thrown awaya. Usually object code is not stored any where. Every time we run the application, the JIT compilation happens and the object code is generated and present in the memory as long as the application is active and running.

Figure 2
Let us turn our attention to simple Hello web application that we have created in our previous article .NET Overiew and see the execution steps involved.
    We execute the application by pressing Ctrl + F5. During this process:
  • our Hello webapplication will be compiled by visual studio and a Hello.dll assembly will be generated. Figure 3 below graphically illustrates the process.
  • Hello.dll assembly contains Intermediate Language.
  • Hello.dll then runs on CLR.
  • JIT compiler with in CLR will convert the Intermediate Language into Object Code which the underlying operating system can understand.
  • Our application executes.
  • When we close the application, the object code is destroyed.

Figure 3
Points to remember about Intermediate Language
  • Intermediate Language(IL) is also called as
    • CIL : Common Intermediate Language
    • MSIL : Microsoft Intermediate Language
    • Managed Code
  • Intermediate Language is also called as Managed code because,CLR manages how IL runs in the memory.
  • C#,J# and VB generate only Intermediate Language(Manage Code)
  • C++ plays a dual role and can generate both managed code(Intermediate Language) as well as native code.
We discussed that when we run the "Hello" web application by pressing Ctrl+F5 visual studio will compile our source code and generate an assembly which will have a .dll extension. To locate where this assembly is generated follow the steps below:

1. In the Page_load event handler write the following code. System.Reflection is a .NET assembly that contain reusable classes which can be used to get some useful information. We will talk about reflection in detail in our later article.
    protected void Page_Load(object sender, EventArgs e)
    {
        Label3.Text = System.Reflection.Assembly.GetExecutingAssembly().Location;
    }
2. Run the application, and when the web page loads in the browser you should see a path as shown in Figure 4 below. This is the location where visual studio has generated the assembly when the application executed.

Figure 4
3. Navigate to the path : "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\hello\c4acd7ac\c64513db\" to locate the assembly that contains the Intermediate Language.
4. To look at the Intermediate Language in the assembly
  • Go to visual studio command prompt by selecting Start->All Programs -> Microsoft Visual Studio 2005 -> Visual Studo Tools -> Visual Studio Command Prompt
  • Change the dirctory in the command prompt to the directory where we have the assembly generated.
  • Type ILDASM NameOfAssembly.dll.
  • You should see Intermediate Language as shown in figure 5.

Figure 5

ILDASM(Intermediate Language Disassembler) is a command line tool that helps too peek inside an assembly and have a look at the generated Intermediate Language. We will have a in depth details about ILDASM and assemblies in our later article.
Common Language Runtime(CLR):
CLR is .NET execution environment with in which .NET applications run.It is a layer between operating system and a .NET application. CLR hosts a JIT(Just In Time) compiler which will convert IL to native code which can be understood by the underlying operating system.

When a .NET application is first run it is a little slow because, the runtime has to convert Intermediate Language code to native code. However the subsequent requests to the application will be faster as Intermediate Language code to native code conversion is no longer required.

Apart from converting Intermediate Language code to native code CLR offers several other benefits as listed below:
  • Memory management
  • Thread management
  • Exception handling
  • Garbage collection
  • Security

Njoy Programming
   ByPrasad Cherukuri