Skip to content

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

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

Closed
1 task done
gurustron opened this issue Feb 3, 2022 · 1 comment · Fixed by #40235
Labels
bug This 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
Milestone

Comments

@gurustron
Copy link
Contributor

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\

@gurustron gurustron changed the title Minimal APIs: Moving handler with single parameter of type HttpContext results in empty response Minimal APIs: Moving handler with single parameter of type HttpContext to separate method results in empty response Feb 3, 2022
@Pilchie Pilchie added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Feb 3, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Feb 3, 2022
@ghost
Copy link

ghost commented Feb 3, 2022

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.

@davidfowl davidfowl added the bug This issue describes a behavior which is not expected - a bug. label Feb 4, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants