The Wayback Machine - https://web.archive.org/web/20220203131204/https://github.com/dotnet/aspnetcore/issues/39956
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
gurustron opened this issue Feb 3, 2022 · 0 comments
Open
1 task done

Comments

@gurustron
Copy link

@gurustron gurustron commented Feb 3, 2022

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\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant