commandlineparser / commandlineparser/commandline

System.InvalidOperationException: 'Sequence contains more than one element'

未关闭
#463 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
4.8k
派生
478
PR 合并指标
30 天内没有已合并 PR

描述

Hello,
I keep getting this Exception and I cannot figure out why.

This is my options class:
`public class BaseOptions
{
[Option(Default = false, HelpText = "Prints all verbose messages to standard output.")]
public bool Verbose { get; set; }
}

[Verb("client", HelpText = "operate as client.")]
public class ClientOptions : BaseOptions
{
[Value(0, MetaName = "dump inventory file",
Default = false,
HelpText = "set this boolean flag for dumping the inventory.")]
public bool DumpInventoryFile { get; set; }

[Value(1, MetaName = "file name",
Default = "inventory.asminventory",
HelpText = "File name for collected inventory information.")]
public string FileName { get; set; }
}`

When I start the program with a FileName, like "client true c:\Temp\server", I get the
"System.InvalidOperationException: 'Sequence contains more than one element'" in
TypeConverter.cs method "ChangeType".

If I start the program without filename, like "client true", it works as it should.

The ChangeType-method expects the parameter "IEnumerable values" to have a count of 1, but in my case it has a count of 2 ("true" and "c:\Temp\server").

Am I doing something wrong? Any help appreciated!

Regards
Bernd

贡献指南

这个仓库没有索引到贡献指南

调研方向

Start with TypeConverter.cs and its ChangeType method, then reproduce the command `client true c:\Temp\server` using the BaseOptions and ClientOptions definitions from the issue. Trace why both arguments reach the conversion of a single value, and verify the expected behavior with and without the filename argument.

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp
领域
cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
28/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。