Open
Description
After updating to the latest release (System.CommandLine v2.0.0-beta3.22114.1), I am now getting the following error at runtime:
Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: --version
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.CommandLine.Parsing.StringExtensions.ValidTokens(Command command)
at System.CommandLine.Parsing.StringExtensions.Tokenize(IReadOnlyList`1 args, CommandLineConfiguration configuration)
at System.CommandLine.Parsing.Parser.Parse(IReadOnlyList`1 arguments, String rawInput)
at System.CommandLine.CommandExtensions.GetDefaultInvocationPipeline(Command command, String[] args)
at System.CommandLine.CommandExtensions.InvokeAsync(Command command, String[] args, IConsole console)
No other changes were made to the app that was previously working. I do use System.CommandLine.NamingConventionBinder
to be compatible with the older CommandHandler.Create
model, could this be the problem?
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
jonsequitur commentedon Mar 29, 2022
Can you provide a code sample to reproduce this?
mmckechney commentedon Mar 29, 2022
Full sample code can be found here: https://gist.github.com/mmckechney/7bd92a4417458fb8b919b44bac5c5b89
In creating this sample I discovered the root of the problem: The use of the
CommandLineBuilder
to add additional help context breaks when you includeUseDefaults()
with the latest Beta3 release.However: I also noticed that if you remove the
UseDefaults()
, the program runs, butPrepend
help text does not get displayed. Is there a new method to prepend to your help message or is this a bug?zachgharst commentedon May 21, 2022
Is there an update on this other than the milestone tag? Do we have any way to work around this? I'm experiencing the same problem. I just want to add a logo and copyright before description.
jonsequitur commentedon May 22, 2022
I'm not seeing this issue when calling
Invoke
on theParser
returned fromCommandLineBuilder.Build
.I do see it when I call
Invoke
directly on theRootCommand
.That should allow people to work around this while we sort out the issue.
perlun commentedon Oct 12, 2022
For reference, this was also spotted by another user some months later: #1791 (comment)
Add workaroud for dotnet/command-line-api/issues/1691
brm
without arguments results in an exception Azure/bicep-registry-modules#175perlun commentedon Oct 12, 2022
I am running into this in my application, but perhaps for slightly different reasons than the rest of you. I have a custom
--version
option defined like this (heavily simplified example):Changing from
.UseDefaults()
to.UseHelp()
works in my case (but some of my application's options still causes other exceptions, likely because of some other incompatibility since the upgrade).5 remaining items