.NET Core vs .NET Framework Code Execution Process

.NET Core vs. .NET Framework Code Execution Process

In this article, I will discuss the .NET Core vs. .NET Framework Code Execution Process. So, we will understand the 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 the .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 the development of applications in multiple languages. 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#, 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 generate the required Metadata. In the .NET Framework, you can check the MSIL Code and Metadata using a tool called ILDASM.

In the .NET Framework, you can see the IL (Intermediate Language) or Microsoft Intermediate Language (MSIL) code in the form of .DLL or .EXE. Suppose you are developing a Console or Desktop application. In that case, it will generate the MSIL or IL Code in the form of .EXE, and if you are developing a Web Application or Class Library Project, 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 compared to the .NET Framework. The steps and process will be mostly the same. Only some of the components in .NET Core will be replaced compared to the .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 when compared with the .NET Framework.

We now have a new series of compilers in .NET Core. The compiler for C# and VB Programming Language is Roslyn; for F# language, it is F# 4.1.

In .NET Core, we don’t have Framework Class Libraries (FCL) or Base Class Libraries (BCL). Instead, we have a different set of class libraries called CoreFx, which we can use to develop the .NET Core Application. So, you can think of CoreFx as 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 automatic memory management, garbage collection, security, machine code generation, and many more functions.

In the next article, I will discuss the Differences Between the .NET Core vs. the .NET Framework. In this article, I try to explain the .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 *