Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

[release/2.2] Startup hook provider #20005

Merged
merged 3 commits into from
Oct 13, 2018
Merged

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Sep 17, 2018

Description

This adds a hook that lets an environment variable specify managed code to be run before Main, allowing early customization in managed code.
Tracking issue: https://github.com/dotnet/coreclr/issues/20004

Customer Impact

This feature will enable Service Fabric to ship updates to their shared assemblies. They intend to use the startup hook to handle resolution for these shared assemblies.

Regression?

Not a regression.

Risk

Low. This shouldn't impact any old functionality.

@@ -364,6 +364,7 @@
<Compile Include="$(BclSourcesRoot)\System\WeakReference.cs" />
<Compile Include="$(BclSourcesRoot)\System\WeakReferenceOfT.cs" />
<Compile Include="$(BclSourcesRoot)\System\CLRConfig.cs" />
<Compile Include="$(BclSourcesRoot)\System\StartupHookProvider.cs" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, alpha order is good because it tends to reduce merge conflicts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here and in master: #20028

}
if (PathInternal.IsPartiallyQualified(startupHook))
{
throw new ArgumentException(SR.Argument_AbsolutePathRequired);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will just say Absolute path information is required. without any indication of what the path was or where it came from.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stack trace will indicate that the exception came from the startup hook path. This is the same exception we throw elsewhere from SPC for non-absolute path info. Sometimes we also include the name of the variable containing the path, but that wouldn't help in this case since it's a local that could be any of the hooks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may make a pass in master in future to add the path (if it exists) to all uses of Argument_AbsolutePathRequired... 😄

@RussKeldorph RussKeldorph added the Servicing-consider Issue for next servicing release review label Sep 18, 2018
sbomer added a commit to sbomer/coreclr that referenced this pull request Sep 18, 2018
jkotas pushed a commit that referenced this pull request Sep 19, 2018
@jamshedd jamshedd added Servicing-more-info and removed Servicing-consider Issue for next servicing release review labels Sep 27, 2018
* 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
@RussKeldorph RussKeldorph added Servicing-consider Issue for next servicing release review and removed Servicing-more-info labels Oct 12, 2018
@sbomer sbomer merged commit 702b0fd into dotnet:release/2.2 Oct 13, 2018
@vivmishra vivmishra added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 16, 2018
@vivmishra vivmishra added this to the 2.2 milestone Oct 16, 2018
@vivmishra
Copy link

Approved for 2.2 RTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants