Skip to content

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

@gurustron

Description

@gurustron

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\

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue describes a behavior which is not expected - a bug.old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions