You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IndexOutOfRangeException in RootCommand ctor #2812
Within my project, an exception ends up thrown in RootCommand's ctor.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.CommandLine.RootCommand.get_ExecutablePath() + 0x4c
at System.CommandLine.RootCommand.get_ExecutableName() + 0x24
at System.CommandLine.RootCommand..ctor(String) + 0x1c
at GSE.CliArgs.Parse(String[]) + 0x6c
at GSE.Entrypoint.Main(String[]) + 0x14
This occurs within the Android (or rather linux-bionic) version of this project, compiled under NativeAOT. Looking at the ExecutablePath getter, this seems to be due to Environment.GetCommandLineArgs() returning an empty array (thus indexing it throws).
This seems to just be a general issue with Linux (maybe other platforms?) when Environment.GetCommandLineArgs() is being used under NativeAOT as a native library (e.g. as a .so file), where it proceeds to return an empty array. Windows ends up working fine under a similar environment (and even manages to get the name of the exe which loads the native dll).
The first element in the array contains the file name of the executing program. If the file name is not available, the first element is equal to String.Empty.
which implies at least 1 element should be present in the array. So this might just rather be a runtime bug.
Activity
[-]IndexOutOfRangeException In RootCommand ctor[/-][+]IndexOutOfRangeException in RootCommand ctor[/+]CasualPokePlayer commentedon May 25, 2026
This seems to just be a general issue with Linux (maybe other platforms?) when
Environment.GetCommandLineArgs()is being used under NativeAOT as a native library (e.g. as a .so file), where it proceeds to return an empty array. Windows ends up working fine under a similar environment (and even manages to get the name of the exe which loads the native dll).Docs for Environment.GetCommandLineArgs do say:
which implies at least 1 element should be present in the array. So this might just rather be a runtime bug.
Improve RootCommand executable name handling (fix dotnet#2812)
Keep NAOT command handling off by default on macOS
Note macOS exclusion for DOTNET_CLI_ENABLEAOT
Restrict NAOT default-on to Windows only (macOS + Linux blocked by co…
Resolve executable name via AppContext when no managed entry point; f…
Improve RootCommand executable name handling (fix dotnet#2812)
Resolve executable name via AppContext when no managed entry point; f…
Document DOTNET_CLI_ENABLEAOT environment variable (#54649)
Keep NAOT command handling off by default on macOS
Restrict NAOT default-on to Windows only (macOS + Linux blocked by co…
Keep NAOT command handling off by default on macOS
Restrict NAOT default-on to Windows only (macOS + Linux blocked by co…
DOTNET_CLI_ENABLEAOT: enabled by default on all platforms (#54735)