C# Program Compilation Steps
C# Program compilation steps are as follows.
- Compiling Source Code into Managed Module.
- Combining newly created managed module into the assembly / assemblies.
- Loading the CLR.
- Executing the assembly in & by CRL.
In .NET framework every program executes (communicate) in an operating system by using CLR (Common Language Runtime).
- Compiling Source Code into Managed Module.
- All languages in .NET framework have their own compiler. Like C# has a C# compiler, JavaScript has a Jscript compiler, etc.
- Whenever source code gets compiled by its appropriate compiler it gets converted into a Managed Module.
- Suppose if we create a console application & compile it then it creates a .exe file. If we create a web application & compile it then it creates .dll files.
- The managed module is standard windows Portable Executable (PE) file that contains the following parts.
- PE Header
It is similar to the common object file format. - CLR Header
This contains the CLR version required to run this managed module, location & metadata. This also contains the entry point of the function i.e. the address of the entry point of the function. - Metadata
This contains table information means variable with its data types and default values, functions/methods which are declared & defined in our program.
In the symbol table all information is stored like the following code snippet:.EXE file also contains Date Time, Owner name, on which operating system this .exe file is created with bit systems like 32 bit or 64 bit. It also contains Magic Number which will get matched whenever we want to execute the .exe file on our computer. If this magic number does not match with the operating system then it will generate an error.- .int i = 25000;
- string str = “Rupesh Kahane”;
(Diagram reference Wikipedia)
4.Loading the CLR
(Diagram reference Wikipedia)
Every program is located on a hard disk. To run/execute each file it should have to come on RAM from hard disk means magnetic address space to electric address space. This is possible by using the help of the Loader.
- It provides the possibility to connect information, systems, people, and devices through software.
- The mscoree.dll file is a Microsoft Runtime Execution Engine.
- It contains the fundamental functions of the.NET framework.
- Functions: quickly build, manage, deploy, & Security enhanced solutions with web services.
- Initializes the CLR
- Locates the managed entry point in the executable assembly’s CLR header, and begins execution.
- This function is called by the loader in processes created from managed executable assemblies.
- For DLL assemblies, the loader calls to _CoreDllMain function.
CLR means a common language runtime. It is the heart of the .NET framework which helps to execute the program on an operating system.
CLR provides some functionalities such as Garbage Collection, Code Verification, Memory Management, Code Access Security, and IL to Native translation.
We can see PE Header, CLR Header, Metadata, and Address Table values by dumpbin.exe:
- First, install it on our local machine (download dumpbin.exe from the internet).
- To see dumpbin.exe location in our local pc.
No comments:
Post a Comment