-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Analyzer] RequestDelegate return value detection #44316
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
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
What does a "bad method" mean? We fixed this in .NET 7. |
A |
That works now. This is why the issue is closed. |
The change was reverted later - #42519 |
So is this about trimming or something else? The change wasn't reverted, just the trimming attributes. |
API Review Notes:
Category: Usage |
Background and Motivation
RequestDelegate
can be used with methods/lambdas that return a value that is then ignored.Delegate signature:
aspnetcore/src/Http/Http.Abstractions/src/RequestDelegate.cs
Lines 6 to 11 in 86c7e01
Because
Task
is the base type ofTask<T>
, generic variance means it's possible to returnTask<T>
from a method that's used withRequestDelegate
. The caller of the delegate never sees the value and it is ignored.Example: #39956
Proposed API
An analyzer that detects using a method or lambda that returns
Task<T>
withRequestDelegate
and warns the user.Usage Examples
Note that an async lambda can't get in this situation and doesn't need to be checked. The compiler detects a return value and prevents the lambda being converted to
RequestDelegate
:Alternative Designs
Risks
The text was updated successfully, but these errors were encountered: