2

I know what it does but I haven't found an explanation of how it is executed. Differently from Java we don't need to call a Virtual Machine executable to run our programs.

In .NET just run the executables normally. Is it a Windows Service? Is it a DLL referenced by .Net executables? Is it bound to operating system kernel? Is it a kind of interceptor like an antivirus? What is it?

Eduardo
  • 5,645
  • 4
  • 49
  • 57
  • The JIT is just one aspect of the VM that runs CLR programs. A conforming CLR VM might not even have a JIT. –  Jan 30 '13 at 00:07
  • 1
    Nope, I suspect this is *not* a duplicate of that. While the original question/tags are confusing (especially the "JIT" stuff), there is a reference made to "don't need to call a Virtual Machine" (e.g. `java theprogram.jar`). –  Jan 30 '13 at 00:08

3 Answers3

3

The Portable Executable format used by Windows NT for executables and later uses Metadata within the PE header to support CLR executables.

Windows, when the .NET Framework is installed, knows about this information, and uses it to launch the CLR with the executable.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
2

It depends on what version of Windows you have. But the basic mechanism is that every .NET assembly contains five bytes of unmanaged code. For an EXE, it is a JMP instruction to _CorExeMain() in c:\windows\system32\mscoree.dll. Which then does the heavy lifting of initializing the CLR and getting the Main() method of your program started.

Later versions of Windows have a loader that knows about the format of a .NET assembly and integrates directly with mscoree.dll. Required to support the very unusual feature that a 32-bit executable can start a 64-bit process. More about that in this answer.

This is the 10,000 feet view. The essential difference between .NET and Java is that a .NET assembly can contain both unmanaged code (like that JMP) and data (the assembly manifest and IL). A Java .class or .jar file is pure data.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

If I recall correctly early versions of .net weren't automatically loaded by windows, but over the years and with more releases of windows the bootstrapping of the process is now seemless.

.Net's CLR is Microsoft's implementation of the CLI Common Language Infrastructure. Mono is another implementation of it.

Technically the CLR is implemented as a COM server component that runs in windows and manages the execution of the .net assemblies.

If you really want to learn the details you should check out Jeffrey Richter's book: CLR via C#

Jason Haley
  • 3,770
  • 18
  • 22