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

Branch + AddAsyncDelegate causes MissingMethodException #1719

Open
dotTrench opened this issue Dec 22, 2024 · 0 comments
Open

Branch + AddAsyncDelegate causes MissingMethodException #1719

dotTrench opened this issue Dec 22, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@dotTrench
Copy link

Information

  • Version: 0.49.1

Describe the bug
AddAsyncDelegate without custom settings throws CommandRuntimeException on invocation.
Spectre.Console.Cli.CommandRuntimeException: Could not resolve type 'Spectre.Console.Cli.CommandSettings'.
---> System.MissingMethodException: Cannot dynamically create an instance of type 'Spectre.Console.Cli.CommandSettings'. Reason: Cannot create an abstract class.

To Reproduce

using Spectre.Console.Cli;

var app = new CommandApp();

app.Configure(cfg =>
{
    cfg.PropagateExceptions();
    cfg.AddBranch("sample", s =>
    {
        s.AddAsyncDelegate("async-test", async context =>
        {
            await Console.Out.WriteLineAsync("Hello from async delegate");
            return 0;
        });
        s.AddDelegate("sync-test", context =>
        {
            Console.WriteLine("Hello from sync delegate");
            return 0;
        });
    });
});

return await app.RunAsync(args);

Invoking the program using sample async-test throws an exception, while invoking using sample sync-test prints "Hello from sync delegate".

Expected behavior
AddAsyncDelegate and AddDelegate should behave in the same way, i.e. just invoke the provided delegate

Additional context

As a workaround it's possible to call AddBranch<EmptyCommandSettings>(...) and get the expected behavior.
AddDelegate currently performs a type check using Type.IsAbstract here to fix #1507. while no such check is done when configuring an async delegate.


Please upvote 👍 this issue if you are interested in it.

@dotTrench dotTrench added bug Something isn't working needs triage labels Dec 22, 2024
@github-project-automation github-project-automation bot moved this to Todo 🕑 in Spectre Console Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant