Skip to content

UseHost() - can't have subcommand "config" #2220

Closed

Description

@seanadams9

When using UseHost() the hosting action sets up a CliDirective with the name "config". If you have a subcommand with the same name "config" parsing fails with:

An item with the same key has already been added. Key: config
System.ArgumentException: An item with the same key has already been added. Key: config
at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at System.CommandLine.Parsing.StringExtensions.g__AddCommandTokens|8_0(Dictionary2 tokens, CliCommand cmd) at System.CommandLine.Parsing.StringExtensions.ValidTokens(CliCommand command, IReadOnlyList1 directives)
at System.CommandLine.Parsing.StringExtensions.Tokenize(IReadOnlyList1 args, CliConfiguration configuration, Boolean inferRootCommand, List1& tokens, List1& errors) at System.CommandLine.Parsing.CliParser.Parse(CliCommand command, IReadOnlyList1 arguments, String rawInput, CliConfiguration configuration)
at System.CommandLine.Parsing.CliParser.Parse(CliCommand command, IReadOnlyList1 args, CliConfiguration configuration) at System.CommandLine.CliConfiguration.Parse(IReadOnlyList1 args)

Activity

  1. added
    bug
    on Jun 12, 2023
  2. self-assigned this
    on Jun 12, 2023
  3. added this to the 2.0 GA milestone on Jun 12, 2023
  4. jonsequitur commented on Jun 12, 2023

    @jonsequitur
    Contributor

    This bug is more general and affects any directive where the name collides with a command defined on the root.

  5. removed this from the 2.0 GA milestone on Jun 15, 2023
  6. removed their assignment
    on Jun 27, 2025
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

    Area-APIbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions