Skip to content

Analyzer: Warn when passing a Task<T> or ValueTask<T> to Minimal API Results.* methods #36408

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

Open
martincostello opened this issue Sep 11, 2021 · 2 comments
Labels
analyzer Indicates an issue which is related to analyzer experience area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing
Milestone

Comments

@martincostello
Copy link
Member

Is your feature request related to a problem? Please describe.

Playing around with Minimal APIs, I wrote some code similar to the below without noticing I'd forgotten to await the method:

app.MapGet("/do-thing", (IThingDoer thing) => Results.Json(thing.DoThingAsync()));

Calling /do-thing then returned some JSON similar to the below:

{"result":{},"id":1,"exception":null,"status":5,"isCanceled":false,"isCompleted":true,"isCompletedSuccessfully":true,"creationOptions":0,"asyncState":null,"isFaulted":false}

Easily fixed by updating the method signature appropriately, but an easy enough mistake to make.

app.MapGet("/do-thing", async (IThingDoer thing) => Results.Json(await thing.DoThingAsync()));

Describe the solution you'd like

An analyzer that warns if a "task-like" type (Task, Task<T>, ValueTask, ValueTask<T>) is passed to one of the static Results methods (like Results.Json(object? data, ...)) for a parameter of type object?.

@mkArtakMSFT mkArtakMSFT 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 Sep 12, 2021
@rafikiassumani-msft rafikiassumani-msft added feature-minimal-actions Controller-like actions for endpoint routing analyzer Indicates an issue which is related to analyzer experience labels Sep 13, 2021
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Sep 13, 2021
@rafikiassumani-msft
Copy link
Contributor

Triage: We will evaluate to commit to this work with other analyzers for .NET7 planning.

@ghost
Copy link

ghost commented Oct 11, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 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.

@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
@captainsafia captainsafia removed the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jun 6, 2023
@captainsafia captainsafia modified the milestones: .NET 8 Planning, Backlog Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer Indicates an issue which is related to analyzer experience area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing
Projects
No open projects
Status: No status
Development

No branches or pull requests

5 participants