What is CLI and CLR

CLR and CLI are basic components of .NET Framework. This article is a basic introduction to .NET Common Language Runtime (CLR) and .NET Common Language Infrastructure (CLI).
 

What Is .NET CLR

 
.NET CLR is an execution engine and is the integral part of .NET Framework that is responsible for executing and managing the lifecycle of an executable. CLR stands for Common Language Runtime and also knows as the runtime. CLR’s responsibility is to mange any code written in .NET languages such as C#, VB.NET, or F#. The code that targets CLR is also knows as the “managed code”.
 
CLR is the common runtime for all .NET languages. Each language that supports .NET must follow a common standard and must emit and attach metadata with every binary, or portable executable (PE). The metadata includes the types, objects, members, and references. The runtime uses metadata to understand types, load types, allocate memory and manages memory lifetime, resolve method invocations, generate native code, enforce security, and set run-time context boundaries.
 
Here is a list of CLR functions: 
  • Automatic memory management with Garbage collection (GC) including releasing unused objects, managing pool of threads, and reserve locations.
  • Cross language interoperability
  • Structured exception handling
  • Code access security
  • Thread execution, thread pooling, and context
  • Debugging
  • Verification and compliance
The following diagram shows the execution model of CLR.
 
Common Language Runtime 
 
Here is a more detailed article on .NET CLR: What is Common Language Runtime
 

Common Language Infrastructure (CLI)

 
The CLR code uses a common type system (CTS) that is based on a common language infrastructure (CLI).
 
CLI is a specification developed by Microsoft that describes the executable code and runtime environment. In simple terms this allows us to use various high-level programming languages on various machines without rewriting the code.
 
CLI is divided into four main components.

 

Common type system (CTS)

 
CTS defines some basic data types and every language that is designed for use with .NET framework should be able to match its data types to these defined basic data types. So when various languages are designed following CTS, they will be able to communicate with each other and this is nothing but cross-language interoperability or communication.
 

Common Language Specification (CLS)

 
CLS is a set of specifications that must be met by every language to be considered as .NET compliant. It is a subset of CTS types and a set of rules. Example: Elimination of pointers and multiple inheritance.
 

Metadata

 
Metadata gives information about all the classes and the class members defined in the assembly. You will learn later what an assembly means.
 

Virtual Execution System (VES)

 
VES loads and runs the programs that are compatible with the CLI using metadata. To make it clear, CLI is a set of specifications for a virtual operating system that is nothing but a Common Language Runtime (CLR).
 
 


Similar Articles