Skip to content

UseCommandHandler not works with sub-class. #1209

Closed
@CzBiX

Description

@CzBiX

codes like this won't work.

abstract class Base : ICommandHandler
{
    protected virtual void Run()
    {}

    public Task<int> InvokeAsync(InvocationContext context)
    {
        Run();
        return Task.FromResult(0);
    }
}

class Sub : Base {}

host.UseCommandHandler<MyCommand, Sub>()

exception:

Unhandled exception. System.Reflection.TargetException: Non-static method requires a target.
   at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions