dotnet/aspnetcore

Minimal APIs: Moving handler with single parameter of type `HttpContext` to separate method results in empty response

Closed this issue · 1 comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Moving Minimal APIs handler with single param of type HttpContext results in empty response.

WebApplicationBuilder builder = WebApplication.CreateBuilder();
WebApplication app = builder.Build();
app.Map("/Fails", Fails);
app.Map("/Fails1", Fails1);
app.Map("/Works", async (HttpContext c) =>
{
    var response = await Task.Run(() => { return "response"; });
    return response;
});
// /WorksToo?someParam=1
app.Map("/WorksToo", Works);
app.Map("/WorksToo1", Works1);
app.Map("/WorksToo2", Works2);
app.Run();
static async Task<string> Fails1(HttpContext context)
{
    var response = await Task.FromResult("response");
    return response;
}
public partial class Program
{
    internal static async Task<string> Fails(HttpContext context) => await Task.FromResult("response");

    internal static async Task<string> Works(HttpContext context, string someParam) => await Task.FromResult("response");

    internal static async Task<string> Works1(HttpContext context, ILogger<Program> _) => await Task.FromResult("response");

    internal static async Task<string> Works2(HttpRequest context) => await Task.FromResult("response");
}

Endpoints named Fails return empty result (chrome, postman, no Content-Type) while others result in response (Content-Type: text/plain; charset=utf-8")

Expected Behavior

All returns the same - response.

Steps To Reproduce

Run the app in the description and call endpoints.

Exceptions (if any)

No response

.NET Version

6.0.101

Anything else?

  • IDE: both VS 2022 and Rider
  • dotnet info:
    .NET SDK (reflecting any global.json):
    Version: 6.0.101
    Commit: ef49f6213a

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

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.