Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
RequestDelegate can be used with methods/lambdas that return a value which is then ignored.
Delegate signature:
|
/// <summary> |
|
/// A function that can process an HTTP request. |
|
/// </summary> |
|
/// <param name="context">The <see cref="HttpContext"/> for the request.</param> |
|
/// <returns>A task that represents the completion of request processing.</returns> |
|
public delegate Task RequestDelegate(HttpContext context); |
Because Task is the base type of Task<T>, generic variance means it's possible to do this:
Task<string> HelloWorld(HttpContext c) => Task.FromResult("Hello " + c.Request.RouteValues["name"]);
// The compiler prefers RequestDelegate overload over the Delegate overload.
// The return value is never used. Not what the user expects.
endpoints.MapGet("/", HelloWorld);
Example: #39956
Describe the solution you'd like
Write an analyzer that detects using a method or lambda that returns Task<T> with RequestDelegate and warns the user.
Additional context
No response
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
RequestDelegatecan be used with methods/lambdas that return a value which is then ignored.Delegate signature:
aspnetcore/src/Http/Http.Abstractions/src/RequestDelegate.cs
Lines 6 to 11 in 86c7e01
Because
Taskis the base type ofTask<T>, generic variance means it's possible to do this:Example: #39956
Describe the solution you'd like
Write an analyzer that detects using a method or lambda that returns
Task<T>withRequestDelegateand warns the user.Additional context
No response