commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Options via inheritance cause a duplicate error

Open dmoonfire opened this issue 10 years ago • 0 comments

I'm using verbs with initialization and encountered a strange problem with options via inheritance.

public abstract class BaseArguments
{
    [Option('d', "data")]
    public string Data { get; set; }
}

[Verb("child")]
public class ChildArguments : BaseArguments
{
}

I get the following error when I try to parse it.

System.InvalidOperationException was unhandled
HResult=-2146233079
Message=Sequence contains more than one matching element
Source=System.Core
StackTrace:
    at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
    at CommandLine.Core.TypeLookup.GetDescriptorInfo(String name, IEnumerable`1 specifications, StringComparer comparer)
    at CommandLine.Core.InstanceBuilder.<>c__DisplayClass16`1.<Build>b__8(String name)
    at CommandLine.Core.TokenPartitioner.<>c__DisplayClass10.<PartitionSwitches>b__e(Token t)
    at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
    at CommandLine.Core.TokenPartitioner.Partition(IEnumerable`1 tokens, Func`2 typeLookup)
    at CommandLine.Core.InstanceBuilder.Build[T](Func`1 factory, Func`3 tokenizer, IEnumerable`1 arguments, StringComparer nameComparer, CultureInfo parsingCulture)
    at CommandLine.Core.InstanceChooser.MatchVerb(Func`3 tokenizer, IEnumerable`1 verbs, IEnumerable`1 arguments, StringComparer nameComparer, CultureInfo parsingCulture)
    at CommandLine.Core.InstanceChooser.Choose(Func`3 tokenizer, IEnumerable`1 types, IEnumerable`1 arguments, StringComparer nameComparer, CultureInfo parsingCulture)
    at CommandLine.Parser.<>c__DisplayClass8.<ParseArguments>b__6()
    at CommandLine.Parser.MakeParserResult[T](Func`1 parseFunc, ParserSettings settings)
    at CommandLine.Parser.ParseArguments(String[] args, Type[] types)
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
InnerException: 

dmoonfire avatar Mar 02 '15 23:03 dmoonfire