dotnet / dotnet/aspnetcore

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

Open
#45,373 11 comments 4 reactions 0 assignees View on GitHub
area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

It seems that issue described in https://github.com/dotnet/aspnetcore/issues/39956 was not fixed but even got worse - Minimal APIs handler with single param of type `HttpContext` results in empty response.

```csharp
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 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](https://user-images.githubusercontent.com/6535969/204880335-e2c1d7ba-227f-4fa2-96dc-9a16b8256b7a.png)

### 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\

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.