Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md

.NET has a concept of a "startup hook", which appears to work fine
on Mono if you set:

env.txt
    DOTNET_STARTUP_HOOKS=StartupHook
(MSBuild)
    <StartupHookSupport>true</StartupHookSupport>
    <RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="StartupHook" />

The startup hook is a managed assembly with a static method, in the
"global" namespace:

class StartupHook
{
    public static void Initialize()
    {
        // ...
    }
}

When the runtime starts, it will call StartupHook.Initialize() before
any other managed code is executed.

dotnet watch (Hot Reload) relies on this feature.

I added a test to Mono.Android-Tests to verify that the startup hook
was called.

This is not yet working on CoreCLR on Android, investigation ongoing.

@jonathanpeppers
Copy link
Member Author

@rolfbjarne do you know if this works on iOS/Catalyst?

@rolfbjarne
Copy link
Member

@rolfbjarne do you know if this works on iOS/Catalyst?

I did a quick test, and it doesn't seem to work, so I filed an issue: dotnet/macios#24492

Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md

.NET has a concept of a "startup hook", which appears to work fine
on Mono if you set:

    env.txt
        DOTNET_STARTUP_HOOKS=StartupHook
    (MSBuild)
        <StartupHookSupport>true</StartupHookSupport>
        <RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="StartupHook" />

The startup hook is a managed assembly with a static method, in the
"global" namespace:

    class StartupHook
    {
        public static void Initialize()
        {
            // ...
        }
    }

When the runtime starts, it will call `StartupHook.Initialize()` before
any other managed code is executed.

`dotnet watch` (Hot Reload) relies on this feature.

I added a test to `Mono.Android-Tests` to verify that the startup hook
was called.

This is not yet working on CoreCLR on Android, investigation ongoing.
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/startup-hook branch from a09103f to 17176cd Compare January 8, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants