Common Language Runtime (CLR) .NET Framework.
Published: 2021-11-23 10:14:02

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**Common Language Runtime (CLR)** is the important feature of .Net. It is also included in .Net5. Basically it is a virtual machine component that take **Intermediate language (IL)** or **Microsoft Intermediate Language (MSIL)**code assembly in **dll** or **exe** format and enable it to run on system.</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">How dose CLR works</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">Here is the basic working of CLR. Let&rsquo;s explain it later</span></span>

1.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">First a developer writes code in any DotNet specific language such as C# or VB.</span></span>
2.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">Then compiler compiles code in **Intermediate Language (IL). **For example if language in C# its compiler is CSC and if language is VB its compiler is VBC.</span></span>
3.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**IL** is then passes to CLR which pass it to **Just In-Time (JIT) **compiler which converts it to machine specific instructions.</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Why to Intermediate Language (IL)</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">As we discussed that compiler compiles code first in **Intermediate Language (IL) **which is half compiled code or partially compiled code. Why it is done so? Is very simple because we do not know in what machine our code will run weather it will run in windows 7, 10 or 11 also we don&rsquo;t know the CPU and machine configurations etc of the system </span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Components of CLR</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">Following are the components of CLR</span></span></span>

1.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">Security Manager</span></span></span>
2.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">JIT Compiler</span></span></span>
3.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">Memory Manager</span></span></span>
4.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">Garbage Collector</span></span></span>
5.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">Exception Manager</span></span></span>
6.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">Common Language Specification (CLS)</span></span></span>
7.  <span style="font-size:11pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:12.0pt">Common Type System (CTS)</span></span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Security Manager</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">This component defines weather the user is allowed to access the assembly or not it also checks what kind of authorities a code has and weather it is safe for the system to run or not.</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">JIT (Just In-Time) Compiler</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">This component converts IL code to binary or machine understandable code. JIT compiles code just before execution saving memory translation.</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Memory Manager</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">This component allocation required memory to objects and variable.</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Garbage Collector</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">We all know that .net provides auto garbage collection during code execution many objects and variables are can be created by code and after some time they become useless and needs to de-allocate from memory this is done by garbage collector. It is a background thread that periodically checks weather any object or variable requires de-allocation or not.</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Exception Manager</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">Try-Catch is a life saver for developer thanks to exception manager of CLR, it redirects code to catch whenever an exception occurs at runtime.</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Common Type System (CTS)</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">.Net Framework supports many languages like C#, VB. Every programming language have different data types and are not supported by other language. So if we want to call a VB code in C# we need a system that make VB types understandable by C#. To make smooth communication between two languages we need **CTS **</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Common Language Specifications (CLS)</span>**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">As we discussed in CTS that dot Net supports multiple programming languages and just like they have their own types they also have their own syntax and in order to make one language to be supported by the other we need an inter mediate that make it possible and this is done by **Common language Specifications (CLS).**</span></span>

<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">**<span style="font-size:16.0pt">Summary</span>**</span></span>
<span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">In this article we learned about the basis of **Common language Runtime (CLR)** one of the most important part in the compilations and Running process of DotNet Framework code. </span></span>