What happens when user click .NET assembly (EXE)?

前端 未结 3 1336
旧巷少年郎
旧巷少年郎 2021-02-04 03:42

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

相关标签:
3条回答
  • 2021-02-04 04:13

    When you double click on a .net .exe assembly:

    • Windows' PE loader kicks in
    • If you're on a Windows >= Windows XP it will detect that the executable is a managed executable and will forward it to .net by calling _CoreExeMain in mscoree.dll (_CoreDllMain if you double clicked on a managed .dll). It can use the assembly configuration file to know which runtime to use.
    • If you're on Windows < Windows XP, the .exe file contains a small native piece of code that will jump to mscoree.dll's _CoreExeMain or _CoreDllMain.
    • Then mscoree.dll initializes the .net runtime, depending on the global configuration, the assembly configuration file, and what not.
    • Then if it's a .exe, it will JIT compile its entry point method, and start executing it.
    0 讨论(0)
  • 2021-02-04 04:18

    You probably wants something like: Microsoft .NET Internals

    http://www.amazon.com/Microsoft-NET-Internals-Tom-Christian/dp/0735626758/ref=sr_1_1?ie=UTF8&s=books&qid=1273233479&sr=1-1

    Or since that's not released yet: Essential .NET, Volume I: The Common Language Runtime

    http://www.amazon.co.uk/Essential-NET-Microsoft-Development-Paperback/dp/0201734117

    0 讨论(0)
  • 2021-02-04 04:28

    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

    0 讨论(0)
提交回复
热议问题