
.NET Project Execution Lifecycle (From Code to Execution)
When you create and run a .NET application, several steps occur internally to transform your source code into a running program. Understanding this sequence helps developers debug better, optimize performance, and answer interview questions confidently.
1. Writing the Source Code
You start by writing code in a .NET supported language such as C#, VB.NET, or F#.
Example: creating a HelloWorld.cs
file in C#.
2. Compilation into MSIL/CIL
The language-specific compiler (e.g., csc.exe
for C#) compiles the source code into
MSIL (Microsoft Intermediate Language), also called CIL (Common Intermediate Language).
This IL code is platform-independent and cannot run directly on the machine.
3. Creation of Assemblies
The compiled IL code is stored inside an Assembly. Assemblies are the basic deployment units in .NET and can be:
- .exe – Executable assemblies
- .dll – Library assemblies
Assemblies also include metadata (information about classes, methods, references) and optional resources (images, config files, etc.).
4. Loading the CLR
When you run the application, the CLR (Common Language Runtime) is loaded. The CLR is the heart of .NET execution. It provides:
- Memory management and Garbage Collection
- Type safety and Security checks
- Exception handling
- Thread management
5. JIT Compilation (IL → Native Code)
The IL code is converted into machine-specific native code by the JIT (Just-In-Time) Compiler. This happens at runtime, just before execution. Types of JIT:
- Pre-JIT – Compiles the entire code at once (used in NGen).
- Eco-JIT – Compiles code on demand, discarding after use.
- Normal JIT – Compiles code on demand and saves it for reuse.
6. Execution of Native Code
After JIT compilation, the program runs as native machine instructions. At this stage:
- The CPU executes the instructions.
- CLR manages resources and memory.
- Garbage Collector (GC) automatically frees unused objects.
- Exceptions are caught and handled if they occur.
7. Role of FCL/BCL
During execution, your application may use thousands of ready-made classes from:
- BCL (Base Class Library) – Core utilities (strings, dates, IO, collections).
- FCL (Framework Class Library) – Extended functionality (web, XML, ADO.NET, etc.).
8. Program Ends
Once the program completes, the CLR ensures proper cleanup of resources, memory is freed by GC, and the application terminates safely.
Complete Sequence Recap
- Write source code (C#, VB.NET, F#)
- Compiler converts to MSIL/CIL
- Code stored in Assemblies (.exe / .dll with Metadata)
- CLR is loaded when program starts
- JIT converts IL to native machine code
- Native code executes on CPU
- CLR manages memory, security, exceptions
- FCL/BCL libraries support advanced features
- Garbage Collector cleans up
- Program terminates safely