3

How does the CLR identify the main method of an application in order to begin the execution?
What exactly is the sequence of operations the CLR takes when you execute a .exe file?

Daniel DiPaolo
  • 55,313
  • 14
  • 116
  • 115
Alavudeen
  • 79
  • 6
  • 3
    I'm having a surprisingly hard time finding an exact duplicate, but there are a number of questions about the `Main()` method that touch on certain aspects. – BoltClock Jul 21 '11 at 19:04

1 Answers1

7

It's a C# standard that the entry point is called Main. When compiled to IL it is marked as .entrypoint which is what the CLR uses to identify the method to start.

(Source: Why is Main method private?)

A .NET executable file is also an ordinary Win32 executable. At the normal Win32 entrypoint a small bootstrap code is placed which starts the CLR. On a pre-WinXP OS, the executable is started as a normal Win32 exe, invoking the boostrap code that starts the CLR. Once started, the CLR looks up the .entrypoint in the IL code and starts execution there. On WinXP and above the OS recognizes the file as a CLR executable and directly invokes the CLR.

(Source: http://www.dotnetperformance.com/downloads/ngen.doc)

Community
  • 1
  • 1
Anders Abel
  • 67,989
  • 17
  • 150
  • 217