Skip to content

[NativeAOT] env var timing at startup #10705

Description

@jonathanpeppers

Android framework version

net11.0-android (Preview)

Affected platform version

.NET 11

Description

There is a timing issue for startup on NativeAOT:

  • If you set an env var specific to the runtime, like $DOTNET_STARTUP_HOOKS
  • NativeAOT runs startup hooks before any of our managed code runs
  • Then our startup code is called, and we populate env vars
  • But then its too late, $DOTNET_STARTUP_HOOKS was already read

Hot Reload doesn't work on NativeAOT, but this could be problematic for other runtime-specific env vars.

To fix, I think we'd have to call Java -> native code, to set env vars earlier at startup.

Steps to Reproduce

Run tests\Mono.Android-Tests\Mono.Android-Tests\Mono.Android.NET-Tests.csproj.

But remove the check for NativeAOT:

<!-- Set STARTUP_HOOKS via RuntimeHostConfigurationOption for MonoVM and NativeAOT (read via AppContext.GetData) -->
<RuntimeHostConfigurationOptionInclude="STARTUP_HOOKS"Value="StartupHook"Condition=" '$(UseMonoRuntime)' == 'true' or '$(PublishAot)' == 'true' " />

To rely on $DOTNET_STARTUP_HOOKS=StartupHook instead.

Did you find any workaround?

Set STARTUP_HOOKS app context switch.

Relevant log output

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: App RuntimeIssues in `libmonodroid.so`.needs-triageIssues that need to be assigned.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions