Skip to content

Route handler filters don't handle all return types #41213

Closed
@BrennanConroy

Description

@BrennanConroy

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}

Metadata

Metadata

Assignees

Labels

bugThis issue describes a behavior which is not expected - a bug.old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions