-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Minimal APIs] async handlers with single HttpContext
parameter are not working
#45373
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
Comments
HttpContext
parameter handlers are not workingsHttpContext
parameter are not working
Triage: This behavior is a result of the change introduced in this PR. We introduced an analyzer for this in .NET 8 at #44048 that we should consider backporting to .NET 7. @JamesNK Thoughts on backporting this? The PR above backports a runtime fix that was addressed in #39956. Note: this runtime behavior also exists in .NET 6. |
Addendum: at least for the OpenAPI-related aspects we are tracking this via #44970. |
@JamesNK Thoughts on a partial revert of https://github.com/dotnet/aspnetcore/pull/42519/files#diff-f8807c470bcc3a077fb176668a46df57b4bb99c992b6b7b375665f8bf3903c94L202-L207? cc: @eerhardt |
My understanding of https://github.com/dotnet/aspnetcore/pull/42519/files#diff-f8807c470bcc3a077fb176668a46df57b4bb99c992b6b7b375665f8bf3903c94L202-L207 is that we were doing "trim unsafe" behavior before that change - specifically we would JSON serialize the So in this case, the options I see are:
|
I'm against reverting the change. These low-level methods are used by app frameworks, e.g. gRPC, and app frameworks should have a simple way to add endpoints that doesn't create warnings. I don't have a problem with backporting the analyzer #44048 |
A workaround (at least for .net 7.0.100) is to force the type to be a simple Delegate instead of a RequestDelegate (for functions with a single HttpContext param)
Response body is populated correctly with all headers, and it even shows up in the generated openapi docs |
@g-jozsef yes it is either casting to "correct" type or adding a parameter, for example |
Thank you for the workaround! I've tested it, and it works perfectly. I appreciate your help. @captainsafia |
At the moment, I don't believe that we would do anything to change the overload behavior here. This issue occurs because the compiler favors the |
Woudn't it be better to partially revert |
Would it be possible to use the new C#13 OverloadResolutionPriorityAttribute to solve this? |
Is there an existing issue for this?
Describe the bug
It seems that issue described in #39956 was not fixed but even got worse - Minimal APIs handler with single param of type
HttpContext
results in empty response.Endpoints suffixed
fails
return empty result while others return "VERB response"In addition only "works" endpoints are recognized by swagger:
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?
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\
The text was updated successfully, but these errors were encountered: