Closed
Description
Filters currently wrap the user delegate in a ValueTask<object?>
before handing off the function to the normal route handling logic. This causes issues with any non object returning methods like void
, Task
, Task<T>
, etc. returning methods.
Void returning method with no-op filter:
void Method() { }
app.MapGet("/method", Method).AddFilter((c, n) => n(c));
Output:
ArgumentException: Expression of type 'System.Void' cannot be used for parameter of type 'System.Object' of method 'System.Threading.Tasks.ValueTask`1[System.Object] WrapObjectAsValueTask(System.Object)' (Parameter 'arg0')
Task returning method with no-op filter:
Task Method() => Task.CompletedTask;
app.MapGet("/method", Method).AddFilter((c, n) => n(c));
Output:
{"result":{},"id":54,"exception":null,"status":5,"isCanceled":false,"isCompleted":true,"isCompletedSuccessfully":true,"creationOptions":0,"asyncState":null,"isFaulted":false}