-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
@@ -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" /> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK thanks
There was a problem hiding this comment.
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... 😄
For consistency with dotnet#20005
* 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
9d35a55
to
1162fe9
Compare
Approved for 2.2 RTM |
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.