commandlineparser / commandline

The best C# command line parser that brings standardized *nix getopt style, for .NET. Includes F# support
MIT License
4.53k stars 477 forks source link

Version 2.9.1 is generating the exception: System.MissingMethodException #819

Open eddynaka opened 2 years ago

eddynaka commented 2 years ago

I was using version 2.7.82 and wanted to update it to 2.9.1 and started to see the following stack:

Unhandled exception. System.MissingMethodException: Method not found: 'Void CommandLine.VerbAttribute..ctor(System.String)'.
   at System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule module, Int32 methodToken, IntPtr[] typeInstantiationContext, Int32 typeInstCount, IntPtr[] methodInstantiationContext, Int32 methodInstCount)
   at System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule module, Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
   at CommandLine.Core.Verb.<>c.<SelectFromTypes>b__22_0(Type type)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.GetCount(Boolean onlyIfCheap)
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
   at CommandLine.Core.InstanceChooser.Choose(Func`3 tokenizer, IEnumerable`1 types, IEnumerable`1 arguments, StringComparer nameComparer, Boolean ignoreValueCase, CultureInfo parsingCulture, Boolean autoHelp, Boolean autoVersion, Boolean allowMultiInstance, IEnumerable`1 nonFatalErrors)
   at CommandLine.Parser.ParseArguments(IEnumerable`1 args, Type[] types)
   at CommandLine.ParserExtensions.ParseArguments[T1,T2,T3,T4](Parser parser, IEnumerable`1 args)

All my options have verbs like this:

[Verb("analyze", HelpText = "Analyze one or more binary files for security and correctness issues.")]
    public class AnalyzeOptions : AnalyzeOptionsBase

And I invoke my options like this:

return Parser.Default.ParseArguments<
                AnalyzeOptions,
                TestOptions>(args)
              .MapResult(
                (AnalyzeOptions analyzeOptions) => new AnalyzeCommand().Run(analyzeOptions),
                (TestOptions testOptions) => new TestCommand().Run(testOptions),
                _ => HandleParseError(args, richResultCode));
elgonzo commented 2 years ago

The API surface of the new library is not entirely identical to the older version. You therefore need to (re)build your project against the new library. (FYI: This commit https://github.com/commandlineparser/commandline/commit/e826508c52814f6f65e0453d75ca4b4072f76b84 changed the signature of the only VerbAttribute constructor from a single string argument to two constructor arguments; and this commit https://github.com/commandlineparser/commandline/commit/fe15c5de0814f293f6b4f8dd3ed90a91b8717786 changed the constructor signature once more...)

eddynaka commented 2 years ago

Well...I built the entire solution and it was built successfully.

elgonzo commented 2 years ago

Hmm, could you perhaps provide a minimal and complete repro? The code snippet you have shown contains some unknowns, like how TestOptions and AnalyzeOptionsBase are being declared...

chrisw000 commented 1 year ago

I experienced this issue... but I had neglected to update all the project references in the solution to 2.9.1

The test project was still referencing 2.8 - and this error was thrown... whoops!