Add startup hook in System.Private.CoreLib (#19486)
* Add startup hook in System.Private.CoreLib
ProcessStartupHooks can be called from the host before the user's Main
entry point. It receives a list of dlls and types containing
Initialize() methods that will be called, making it possible to inject
managed code early during startup.
* Allow ! in assembly path for startup hook and other changes
Also:
- Report full assembly path when startup hook assembly is not found
- Remove unnecessary assert
- use Type.Delimiter instead of "."
* Use C# 7 tuple syntax and remove assert
* Improve error handling
Throw MissingMethodException only when there aren't any Initialize
methods at all.
When there are Initialize methods with incorrect
signatures (parameters, return type, visibility, or instance methods),
throw invalid signature error.
This should improve diagnosability of this feature.
* Remove eager check for missing startup hook assemblies
* Require full assembly path and use Split(char) overload.
* Remove startup hook type syntax
The type is now required to be "StartupHook" (in the global
namespace).
* Add assembly path to startup signature exception
With a hard-coded type name, printing the type.method of the startup
hook in the exception will no longer be much of an aid in debugging
startup hook signature issues. Adding the assembly path makes it clear
which startup hook had the problem.
* Use const strings
* Call startup hook inside ExecuteMainMethod
This way it will be called when the application is executed, but not
during other uses of hosting apis that go through
coreclr_create_delegate. This change will ensure that the threading
state is set based on attributes in the main method, before the
startup hooks run.
* Run startup hooks after setting root assembly and other fixes
- Run startup hooks after setting the appdomain's root
assembly (visible in Assembly.GetEntryAssembly()
- Make the class static
- Remove debug output
- Don't allocate an empty ARG_SLOT array
* Allow non-public Initialize method, adjust coding style
* Remove overly-specific assert