Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with Option with IEnumerable<string> broken - Sequence contains more than one element #377

Open
ivberg-zz opened this issue Dec 7, 2018 · 5 comments

Comments

@ivberg-zz
Copy link

@ivberg-zz ivberg-zz commented Dec 7, 2018

Running the latest commandlineparser v2.3.0 on .Net Core 2.1.

The library example doesn't seem to work at all parsing IEnumerable
[Option('r', "read", Required = true, HelpText = "Input files to be processed.")]
public IEnumerable InputFiles { get; set; }

If you specify --read file1 file2 you get this exception:

System.InvalidOperationException
HResult=0x80131509
Message=Sequence contains more than one element
Source=System.Linq
StackTrace:

System.Linq.dll!System.Linq.Enumerable.Single<System.Type>(System.Collections.Generic.IEnumerable<System.Type> source) Line 45 C#
CommandLine.dll!CommandLine.Core.InstanceBuilder.Build.AnonymousMethod__0_23(CommandLine.Core.SpecificationProperty sp) Unknown
CommandLine.dll!CommandLine.Core.ReflectionExtensions.SetProperties.AnonymousMethod__0(System.__Canon current, CommandLine.Core.SpecificationProperty specProp) Unknown
System.Linq.dll!System.Linq.Enumerable.Aggregate<CommandLine.Core.SpecificationProperty, LogMerger.Program.Options>(System.Collections.Generic.IEnumerable<CommandLine.Core.SpecificationProperty> source, LogMerger.Program.Options seed, System.Func<LogMerger.Program.Options, CommandLine.Core.SpecificationProperty, LogMerger.Program.Options> func) Line 55 C#
CommandLine.dll!CommandLine.Core.InstanceBuilder.Build.AnonymousMethod__16() Unknown
CommandLine.dll!CommandLine.Core.InstanceBuilder.Build.AnonymousMethod__7() Unknown
CommandLine.dll!CommandLine.Parser.ParseArguments<LogMerger.Program.Options>(System.Collections.Generic.IEnumerable args) Unknown

@ivberg-zz
Copy link
Author

@ivberg-zz ivberg-zz commented Dec 7, 2018

Actually, this was an issue instead with Parsing a Dict
public Dictionary<string, string> Dict { get; set; }

Is this supported?

@nemec
Copy link
Collaborator

@nemec nemec commented Dec 7, 2018

No, unfortunately dicts are not supported

@ericnewton76
Copy link
Member

@ericnewton76 ericnewton76 commented Dec 12, 2018

A dictionary would be hard to support... what generates the keys for the values?

I would believe this is undefined in the getopt specs that this library strives to follow.

@ivberg-zz
Copy link
Author

@ivberg-zz ivberg-zz commented Dec 12, 2018

I think you are correct Eric that it would be hard to support. I think this is more about protecting against dumb new user and a clearer exception behavior than implementing support :). As a C# dev, Dictionary is popular and for better or worse, it's what I expected/hoped to use here as one of the cmd line options. The above is actually misleading, as I thought the IEnumerable is what was causing the issue, but instead the Dict used as another possible cmd-line parameter (turns out didn't need it)

My suggestion is the user adds odd or not supported stuff, that we have a clearer exception than
System.InvalidOperationException - Message=Sequence contains more than one element

@ericnewton76
Copy link
Member

@ericnewton76 ericnewton76 commented Jan 23, 2019

Indeed. The error is misleading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.