Add startup hook in System.Private.CoreLib (#19486)
authorSven Boemer <sbomer@gmail.com>
Fri, 31 Aug 2018 00:24:11 +0000 (17:24 -0700)
committerGitHub <noreply@github.com>
Fri, 31 Aug 2018 00:24:11 +0000 (17:24 -0700)
commit1c47703a3d548e5f3293a11d98747dd83bf429f1
tree5a412f8dca423cf33a18d8d748d6688cc6e6037e
parent35ead994ccde0cf2faaf1786af49d5b9ed523074
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
src/System.Private.CoreLib/Resources/Strings.resx
src/System.Private.CoreLib/System.Private.CoreLib.csproj
src/System.Private.CoreLib/src/System/StartupHookProvider.cs [new file with mode: 0644]
src/vm/assembly.cpp
src/vm/mscorlib.h