19

I am trying to get something clarified.

  1. When a .NET console application is run, does mscorlib.dll/mscoree.dll get loaded in the process's virtual address space?

  2. mscorlib.dll and mscoree.dll (CLR) are not managed dlls. Is that correct?

Also, what is a good resource to understand more about how a .NET program is executed?

Nemo
  • 4,601
  • 11
  • 43
  • 46

3 Answers3

27

Yes. You'll always get mscoree.dll loaded, that's the bootstrapper for the default CLR host. It is an unmanaged DLL. Every .NET assembly contains a wee bit of native code, just a jump into that DLL. It does however get loaded by recent Windows versions directly, the OS loader has .NET awareness built-in. You can see it in the Debug + Modules window when you turn on the unmanaged debugging option, Project + Properties, Debug tab. You'll then also see mscorjit.dll, mscorwks.dll and msvcr80.dll, three other chunks of native code that are required to run managed code. Respectively the just-in-time compiler, the CLR and the C-runtime support library. They have different DLL names in .NET 4.

Technically it is possible to not get mscorlib.dll loaded, the compiler has the /nostdlib option to avoid a reference to that assembly. Practically that only works if you provide a substitute, that's how Silverlight gets compiled for example. It is otherwise a mixed-mode assembly with some native code but mostly managed code. There's a separate version of it for the 64-bit framework because of that. You'll also see mscorlib.ni.dll with unmanaged debugging enabled, that's the ngen-ed version of the assembly.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
7

I would recommend to read the Jefrey Richter's book CLR via C#. It provides very clear explanation what is going on under the hood :)

Also yoг may find this question helpful: Why is an assembly .exe file?

Community
  • 1
  • 1
the_joric
  • 11,986
  • 6
  • 36
  • 57
4

.Net Executable is no different than any other PE files. So like every imported dlls in native executable, mscorlib.dll is loaded in the Process virtual space of .net executable. If it interests you, you can read about PE file format here

crypted
  • 10,118
  • 3
  • 39
  • 52