Consider we have .NET Winforms application or Console Application. Can anyone tell me what will happen step-by-step until the WinForm or Console Application is launched. I would like know the internals - like how EXE will communicate with Framework, what is the role of CLR, what happens in case of exception while launching applicaiton itself.etc...
NET-based applications. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. Assemblies take the form of executable (.exe) or dynamic link library (. dll) files, and are the building blocks of . NET applications.
NET Framework when we compile a Console Application or a Windows Application, it generates EXE, whereas when we compile a Class Library Project or ASP.NET web application, then it generates DLL. In.NET framework, both EXE and DLL are called assemblies.
An assembly is a file that is automatically generated by the compiler upon successful compilation of every . NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated.
In the Microsoft . NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. There are two types: process assemblies (EXE) and library assemblies (DLL). A process assembly represents a process which will use classes defined in library assemblies. .
When you double click on a .net .exe assembly:
The MSCoreEE.dll (MSCore Execution Engine.Dll only one instance for one machine) Say for example when a .Net assembly / .exe is double clicked or launched, the OS will load the windows loader which will inturn load the PE header (Portable executable) [in case of win32 executable, the PE header will contain the address of the bootstrap (static Main()) from where it will load and execute the main method, where as in .Net, the bootstrap will contain the address of MSCoreEE.Dll which will be present in C:\Windows\System32\mscoree.dll which will get executed and load the .Net runtime for which the .net assembly was targeted for. There can be multiple versions of .Net runtime installed on the machine, however, there will be only one instance of mscoreee.dll to load the specific runtimes.
The CLR will create the first APP domain itself and load the assembly (if the assembly didn’t create additional app domains in code)
The CLR creates 3 Application Domains internally 1. System App Domain a. is responsible to load Shared and Default application domains, also loads mscorelib.dll to shared app domain b. Create 3 seperates instances of Exceptions i. Fatal engine exception ii. Stack overflow exception iii. Out of memory exception (very important, the CLR precreates “out of memory” exception bcose when developer thinks the application can go out of memory and wants to write the exception to a log file, creating out of memory exception will take place because there was no memory left to create a new instance of this exception, so, CLR precreates this exception for future use in the application 2. Shared App Domain a. Contains the mscorlib.dll b. Other Common libraries which is used by other app domains c. However, the developer can’t push custom Dll’s into the shared app domain as its not controllable from outside of CLR, the CLR hosts these dll’s and CLR itself cannot be controlled of how it is hosted by a developer however its possible using some COM interfaces where the developer can host the CLR customary 3. Default App Domain a. All user binaries the .exe’s, Dlls gets loaded here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With