As we learned about COM and other technologies and their related problems in the previous section, Microsoft designed a new framework as a solution to all those problems, which was different from all its previous programming languages. This framework was named the .NET Framework, which is to develop completely Future Proof Programming Architecture, achieve code portability between programming languages and support various types of Internet-Based Software, i.e., almost all types of needs only. It was designed to be completed by the same framework and same programming language. The .NET Framework can be represented as a simple diagram as follows:
.NET Framework Working
Run Time and Compile-Time Services were included to run any .NET Application in the .NET Framework. Compile Time Services are those services that are useful to the software developer at the time when he is compiling any software. At the same time, Run-Time Services are useful while executing in the memory of an application.
Servers, COM, COM+, DCOM, Message Queuing, Internet Information Server, Windows .NET Server, SQL Server, etc.… Services are included under Compile-Time and Run-Time Services, whereas if we use Visual Studio for Software Development, then the IDE of Visual Studio is also a part of these services.
At the core of the Run-Time Execute of any .NET Application Code is always the CLR (Common Language Runtime), which is a Virtual Machine similar to Java’s JVM. This CLR runs like a process on the computer on which the .NET Framework is installed.
A virtual Machine works like a virtual computer, which is installed on the current operating system, and this virtual computer runs any .NET application code.
Therefore, if a CLR is designed for Linux or macOS Operating System, then any .NET program developed on any Operating System and any Computer Hardware Architecture can be installed on any other Operating System and Computer Hardware with CLR exactly the same. It can be run in the same way, the way Java programs are run on any computer with JVM in Platform and Architecture Neutral way.
When a .NET application is compiled, the . EXE or .DLL file that is generated is called PE (Portable Executable) code because this code can be run on any other computer with CLR, and this code Always runs in a CLR only. That is, on the computer on which the .NET Platform is not installed, these PE Code Files cannot be run on that computer.
When a program was compiled in all other programming languages of Microsoft, a native machine code file of those programs was created, due to which that code was run only on that computer.
But when a .NET Application Program is compiled by the .NET Platform Supported Programming Language, the file generated is not a Native Machine Code File, but an Intermediate Byte Code File, which is called MSIL (Microsoft Intermediate Language) or IL is known.
This MSIL Code File is actually very similar to Java’s Byte Code Class File, which is neither completely sourced code nor completely Machine Dependent Native Binary Code. Rather there is a middle position file, which can be run on every computer on which CLR is installed, in the same way as Java’s Byte Coded Class File can be run on every computer, On which JVM is installed.
The codes which are loaded in the CLR to be executed, those codes are called an assembly, and this assembly is a collection of one or more files. All the files in an assembly are deployed like a single unit. Included in the assembly can be Portable Executable (.EXE, .DLL, .BMP) files as these files, while any one of these files has an MSIL part named MENIFEST.
This MENIFST file contains necessary information about all the other files of the assembly, all the classes, and other data types specified in those files, which is called METADATA (Data about Data). Also, in this menu, there is also information about how to use the various files, classes, data types, etc., of the assembly.
When the CLR loads an assembly into memory for use, only the MENIFEST is compiled into memory. At the same time, the methods of Data Types, i.e., Classes, are compiled and cached in the cache memory only when they are actually needed in the application program. Due to this arrangement, .NET applications load faster in memory and use fewer resources. This process is called Just-In-Time (JIT) Compiling.
When applications need to release memory, that is, when we terminate a .NET application program, a part of the CLR named Garbage Collector (GC) automatically frees up the resources used by that .NET application. Works of.
As a result, developers no longer need to worry about problems like memory leakage. Because in a .NET application, as soon as there is no variable referencing an object, the GC of the CLR automatically frees the memory of that object. That is, as soon as the need for an object in the current .NET application ends, the GC destroys it.