Interview Questions For Experienced and Beginner .NET Professionals Series Part 1

What is  IL code, CLR, CTS, CLS, JIT ?

How Exactly Dot Net application compiles and Run?

  1. We write our code in C# or VB.net
  2. Then we compile our program then the compiler will convert our C# or VB.Net program into half compile code i.e IL (Intermediate Language ).
  3. When you click on Exe .net execution engine start then CLR gets this half compile code  and gives to JIT
  4. A machine can’t understand Intermediate code so JIT goes line by line and convert half compile code into machine-specific instruction.
  5. Finally, your application executed.

Compilation and Execution Process Of Dot Net Application
Compilation and Execution Process Of Dot Net Application

IL Code- Intermediate Language

This code used in .net framework to generate machine-independent code as an output of the compilation.

It is CPU independent half compile code.

Why we need half compile code and why not in one go it convert to machine-specific instruction?

When we creation application we don’t know which windows version is installed in client machine like window XP, windows vista, window 9,10 like that. Also at the time of development, we don’t know the CPU configuration and other machine details.

IL Code in .Net
IL Code in .Net

CLR (Command Language Runtime)

It is the heart of the .Net framework after the compilation process CLR plays the main role in running your application

  1. Garbage collection
  2. Class Load
  3. CAS code access and code verification
  4. Gives IL code to JIT

CTS (Common Type System)

In .net framework umbrella, there are so many languages present and there might be condition code in one language you need to access in another language so there is a need for smooth communication between these languages we need a common type system.

The common type system ensures that the data type defined in 2 different languages gets compiled into one common type.

Suppose you declared an int variable in c# and integer in VB.net then when it compiles into IL code both variables are compiled into int32. This is CTS.

CLS (Common Language Specification)

It is a subset of CTS. It is a specification and whatever language you used should follow the common specification. It is guidelines that specify if it follows guidelines given by .net framework then it will easily be consumed by .net support language.

How you define your code is CLS compliance?

First, go to assembly.info class and add a tag [assembly: CLSCompliant(true)] it means CLS compliant is enabled for this assembly. This is used when you write code and compiles that code then if it doesn’t follow the compliance then it will throw a warning.

JIT (Just In Time)

JIT translates the MSIL code of an assembly into native code and for that, it uses the CPU architecture of the target machine. There are different types of JIT

  1. Pre JIT
  2. Econo JIT
  3. Normal JIT

Pre JIT

In a single run it will translate all source code into native code. It is done at the time of deployment and in .net it is called “Ngen.exe”.

Ngen.exe
Ngen.exe

ngen.exe install
ngen.exe install

The above command is will convert your application into machine language but conversion is as per machine specific.

Ngen stands for Native Image Generator.

Econo JIT

It will compile only those methods which are called at run time and after execution, it will remove from memory. It mainly used in mobile applications.

Normal JIT

It compiles only those methods which are called at run time. When the first-time compilation is done it is saved in cache memory. If you again call this method it will not compile this method rather than it will take from cache memory. When you run your application from windows normally it uses Normal JIT. To check this add .NET CLR JIT counters in performance counter and check value fluctuating.


GitHub Projects Link : – https://github.com/SagarJaybhay/DotNetDemos


Sagar Jaybhay, from Maharashtra, India, is currently a Senior Software Developer. He has continuously grown in the roles that he has held in the more than seven years he has been with this company. Sagar Jaybhay is an excellent team member and prides himself on his work contributions to his team and company as a whole.

Related posts