Skip to content

Possible bug in beta5 System.CommandLine API #2634

Closed

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


[severity:It’s more difficult to complete my work]
There is a Command.SetAction that takes a Func<ParseResult, Task>. I believe this should be Func<ParseResult, Task<int>>.

When converting from the old API, I ended up with an function that returns a Task<int>. This was silently passed to the Func<ParseResult, Task> version, which silently ate the return value and returned 0 instead.

Workaround: Use the override that also takes a cancellation token.

If you want to keep the Func<ParseResult, Task> version, that’s fine, as long as you also add a Func<ParseResult, Task<int>>. When this issue bit me during conversion from the old to the new API, it took some debugging to get to the bottom of.

Aside from that, the new API is a distinct improvement over the old one.


Original Comments

Feedback Bot on 7/4/2025, 04:24 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Activity

  1. transferred this issue fromdotnet/runtimeon Jul 22, 2025
  2. mikechristiansenvae commented on Jul 24, 2025

    @mikechristiansenvae

    Edit: Nevermind, I see that it only works if you accept the cancellation token!

    You can use an explicit return type

    command.SetAction(async static Task<int> (parseResult, cancellationToken) =>
        {
            // Do your stuff
        }
    );
    
  3. added 4 commits that reference this issue on Jul 28, 2025
    bce9423
    a21dc61
    359c5d2
    0d1cc49
  4. petterh commented on Jul 28, 2025

    @petterh
    Contributor
  5. added a commit that references this issue on Jul 28, 2025
    0a63bad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions