Skip to content

Support custom task types in Minimal API endpoints #55118

Description

@ericmutta

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to map a minimal API endpoint as follows:

  ArgApp.MapPost("/api/create-account", CreateAccount.HandleHttpAsync);

...the endpoint itself is defined with this signature:

 public static async AwaitOnceTask<Response> HandleHttpAsync(HttpRequest ArgRequest, IServiceProvider ArgServices) { }

When I try to run my app, I get the following exception message and stack trace:

System.NotSupportedException: Unsupported return type: AwaitOnceTask<CreateAccount.Response>
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.PopulateBuiltInResponseTypeMetadata(Type returnType, EndpointBuilder builder)
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgumentsAndInferMetadata(MethodInfo methodInfo, RequestDelegateFactoryContext factoryContext)
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.InferMetadata(MethodInfo methodInfo, RequestDelegateFactoryOptions options)
         at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.CreateRouteEndpointBuilder(RouteEntry entry, RoutePattern groupPrefix, IReadOnlyList`1 groupConventions, IReadOnlyList`1 groupFinallyConventions)
         at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.get_Endpoints()

The problem seems to be the return type AwaitOnceTask<CreateAccount.Response> which uses a custom task type I have created called AwaitOnceTask<T>.

Describe the solution you'd like

The docs currently say that:

Minimal endpoints support the following types of return values:

  1. string - This includes Task<string> and ValueTask<string>.
  2. T (Any other type) - This includes Task<T> and ValueTask<T>.
  3. IResult based - This includes Task<IResult> and ValueTask<IResult>.

...this means support for async endpoints is already included but seems to be hardcoded to just Task<T> or ValueTask<T> . It would be great if the logic in Microsoft.AspNetCore.Http.RequestDelegateFactory was written to support any task type that can be defined in C#, not just the native Task<T> or ValueTask<T>.

Additional context

No response

Activity

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

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdffeature-rdg

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions