Difficulty: Medium
Correct Answer: Source code is compiled into Intermediate Language and metadata in an assembly, and at runtime the common language runtime uses just in time compilation to convert IL into native machine code that executes under the control of the runtime.
Explanation:
Introduction / Context:
The .NET platform uses a two stage compilation model that separates language specific compilation from machine specific execution. Understanding this model is important for grasping how features such as cross language interoperability, security, and garbage collection are implemented. This question asks you to describe how a .NET application moves from source code to running native instructions.
Given Data / Assumptions:
- The application is written in a .NET language such as C sharp or Visual Basic.
- A language compiler such as csc is available.
- The target environment includes the common language runtime CLR.
- Assemblies are generated in DLL or EXE form containing Intermediate Language IL and metadata.
Concept / Approach:
In the first step, the language compiler takes source code and produces an assembly that contains IL instructions and metadata that describe types, methods, and references. IL is a CPU independent instruction set designed for the CLR. In the second step, when the application runs, the CLR loads the assembly and uses a just in time JIT compiler to translate IL for each method into native machine code for the current processor. This native code runs under the supervision of the CLR, which provides services such as security checks and garbage collection.
Step-by-Step Solution:
Step 1: The developer writes source code in a .NET language and invokes the compiler, either directly or through the build system.
Step 2: The compiler parses the code, performs type checking, and emits an assembly that contains Intermediate Language instructions and rich metadata describing the program structure.
Step 3: At execution time, the user starts the application, and the CLR loader locates and loads the main assembly and any referenced assemblies into memory.
Step 4: When a method is called for the first time, the JIT compiler compiles its IL into native machine code specific to the processor architecture.
Step 5: The native code executes under CLR management, which handles memory allocation, garbage collection, exception handling, and other runtime services.
Verification / Alternative check:
Tools such as ILDasm allow you to inspect IL in compiled assemblies, demonstrating that source code is not compiled directly to machine instructions. Performance tools and documentation also discuss JIT compilation and how IL is compiled on demand at runtime. These observations confirm that the .NET execution model uses IL plus JIT compilation under the control of the CLR.
Why Other Options Are Wrong:
Option B is wrong because .NET is not a pure interpreter for source code; it requires compilation to IL. Option C is incorrect since .NET applications rely on the operating system and CLR, not on direct microcode execution. Option D is false because only web pages are rendered as HTML in browsers, and .NET source code is not converted to HTML for execution.
Common Pitfalls:
A common misunderstanding is to think that IL is interpreted directly without any native compilation, which can lead to confusion about performance. Another pitfall is assuming that JIT compiled code is identical across all machines, when in fact it can be optimized for the specific processor. Understanding the two stage compilation pipeline helps when tuning performance, analyzing startup time, and reasoning about cross platform behavior with runtimes such as .NET Core.
Final Answer:
In .NET, source code is compiled into Intermediate Language and metadata stored in assemblies, and at runtime the common language runtime loads these assemblies and uses just in time compilation to translate IL into native machine code that runs under CLR management.
Discussion & Comments