This is a detail of the language, the CLR simply reads the EntryPointToken value from the assembly header and does not check the availability of the method with this token. The main call is _AppDomain.ExecuteAssembly (). Therefore, we need to refer to the C # language specification, section 3.1 explicitly states the accessibility rule:
In C #, each method must be defined as a member of a class or structure. Typically, the declared availability (§3.5.1) of a method is determined by the access modifiers (§10.3.5) specified in its declaration, and similarly, the declared type availability is determined by the access modifiers specified in its declaration. In order for this method of this type to be available for invocation, both the type and the member must be available. However, the entry point of the application is a special case. In particular, the runtime can access the application entry point regardless of its declared availability and regardless of the declared availability of its type inclusion declarations .
The bold section documents what the CLR does with the EntryPointToken. The C # compiler can check availability if it wants to, but doesn’t.
Hans Passant Mar 18 '12 at 19:18 2012-03-18 19:18
source share