.NET Core vs .NET Framework Code Execution Process

.NET Core vs. .NET Framework Code Execution Process

In this article, I am going to discuss .NET Core vs. .NET Framework Code Execution Process. So, we will understand NET Core Application Execution Process by comparing it with the .NET Framework Application Execution Process and try to understand what changes have been made in .NET Core.

.NET Framework Code Execution Process:

Let us first discuss the NET Framework Application Execution Process. The code execution process of the .NET Framework Application includes the following 4 steps.

  1. Choosing a Compiler
  2. Compiling Your Code to MSIL
  3. Compiling MSIL to Native Code
  4. Running Native Code

For a better understanding, please have a look at the following diagram.

.NET Core vs .NET Framework Code Execution Process

Choosing a Compiler:

.NET Framework supports multiple languages to develop applications. And each programming language has its own compiler. So, based on the programming language, the respective language compiler will compile your source code. For example, if you are using C# as the programming language, then the compiler will be CSC, and if the programming language is VB, then the compiler will be VBC. Similarly, if the programming language is F#, then the compiler will be FSC.

Compiling Your Code to IL or MSIL Code:

Once you decide programming language, then using a programming language, you will write the code, which is nothing but your source code. Then the respective language compiler will compile the source code into IL (Intermediate Language) or Microsoft Intermediate Language (MSIL) code and generates the required Metadata. In .NET Framework, you can check the MSIL Code and Metadata using a tool called ILDASM.

In .NET Framework, you can see the IL (Intermediate Language) or Microsoft Intermediate Language (MSIL) code in the form of .DLL or .EXE. If you are developing Console or Desktop application, then it will generate the MSIL or IL Code in the form of .EXE, and if you are developing Web Application or Class Library Projects, then you will get the MSIL or IL Code in the form of .DLL. Intermediate Language code is also called managed code. This is because CLR manages the code that runs inside it.

Compiling MSIL to Native Code:

Once the respective language compiler generates the MSIL or IL Code, then at runtime or at execution, the Just-in-Time (JIT) compiler of CLR will convert the Intermediate Language (IL) code into native code (Machine Code or Binary Code), which the underlying operating system can then execute.

Running Code:

The Common Language Runtime (CLR) provides the infrastructure that enables the execution to take place and services to the managed code that can be used during execution.

During execution, managed code receives services such as automatic memory management, garbage collection, security, interoperability with unmanaged code, cross-language debugging support, and enhanced deployment and versioning support.

Note: In .NET Framework, we have BCL (Base Class Libraries) or FCL (Framework Class Libraries), using which we can develop .NET Framework Applications.

.NET Core Code Execution Process:

Now, let us see how .NET Core Code Execution takes place as compared to .NET Framework. Mostly the steps and process are going to be the same. Only some of the components in the .NET Core are going to be replaced as compared to .NET Framework. For a better understanding, please have a look at the following diagram.

.NET Core vs .NET Framework Code Execution Process

As you can see in the above image, the process remains the same. Only a few components are changed as compared with .NET Framework.

In .NET Core, we now have a new series of compilers. For C# and VB Programming Language, the compiler is Roslyn; for F# language, the compiler is F# 4.1.

In .NET Core, we don’t have Framework Class Libraries (FCL) or Base Class Libraries (BCL). Here, we have a different set of class libraries called CoreFx which we can use to develop the .NET Core Application. So, you can think, CoreFx is the reimplementation of Framework Class Libraries (FCL) or Base Class Libraries (BCL) in .NET Core.

In .NET Core, we now have a new run time called CoreCLR, which provides the Runtime Environment for .NET Core Application Execution. Also, a new version of the JIT compiler called RyuJIT is responsible for converting the MSIL or IL Code into Native Code or Binary Code, which can be understood and executed by the Underlying Operating System.

Now the obvious question that should come to your mind is why we have the reimplementation of all these components that we already have in the .NET framework. So, the answer is the same as why Microsoft implemented .NET Core, i.e., for Open-Source and Cross Platform.

.NET Core Composition:

The .NET Core Framework is composed of the following parts:

  1. CLI Tools: A set of tooling for development and deployment using the Command Line Interface.
  2. Roslyn:.NET Core Compiler for C# and VB.NET Programming Languages.
  3. CoreFx: A Set of Framework Libraries using which we can develop .NET Core Applications.
  4. CoreCLR: A RyuJIT-Based CLR (Common Language Runtime). CoreCLR is the Execution Engine in .NET Core, performing functions such as automatic memory management, garbage collection, security and generating the machine code, and many more.

In the next article, I am going to discuss the Differences Between .NET Core vs. .NET Framework. Here, in this article, I try to explain .NET Core vs. .NET Framework Code Execution Process. I hope you enjoy this .NET Core vs. .NET Framework Code Execution Process article.

Leave a Reply

Your email address will not be published. Required fields are marked *