Skip to content

[Minimal APIs] async handlers with single HttpContext parameter are not working #45373

Open
@gurustron

Description

@gurustron

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

It seems that issue described in #39956 was not fixed but even got worse - Minimal APIs handler with single param of type HttpContext results in empty response.

app.MapPost("testpost_works", async (HttpContext context, CancellationToken ct) => await Task.FromResult(context.Request.Method + " response"));
app.MapPost("testpost_fails", Handler);
app.MapGet("testget_works", async (HttpContext context, CancellationToken ct) => await Task.FromResult(context.Request.Method + " response"));
app.MapGet("testget_fails1", async (HttpContext context) => await Task.FromResult(context.Request.Method + " response"));
app.MapGet("testget_fails2", Handler);

async Task<string> Handler(HttpContext context) => await Task.FromResult(context.Request.Method + "response");

Endpoints suffixed fails return empty result while others return "VERB response"

In addition only "works" endpoints are recognized by swagger:

image

Expected Behavior

All endpoints return "VERB response"

Steps To Reproduce

Use Minimal APIs defined above.

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

dotnet --info
.NET SDK:
Version: 7.0.100
Commit: e12b7af219

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100\

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions