Skip to content

IndexOutOfRangeException in RootCommand ctor #2812

Closed

Description

@CasualPokePlayer

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).

Activity

  1. changed the title [-]IndexOutOfRangeException In RootCommand ctor[/-] [+]IndexOutOfRangeException in RootCommand ctor[/+] on May 24, 2026
  2. CasualPokePlayer commented on May 25, 2026

    @CasualPokePlayer
    Author

    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:

    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.

  3. added a commit that references this issue on Jun 17, 2026
    1ae15fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions