Skip to content
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

Add explicit conversion for value-type returning handlers with filters #57428

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Aug 20, 2024

Addresses #52128.

This PR fixes a bug with the handling of value type-returning handlers that are used in conjunction with endpoint filters. Such as:

var app = WebApplication.Create();

app
	.MapGet("/", () => { return 1; })
	.AddEndpointFilter(async (context, next) => await next(context));

app.Run();

This currently throws:

ArgumentException: Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' of method 'System.Threading.Tasks.ValueTask`1[System.Object] WrapObjectAsValueTask(System.Object)' (Parameter 'arg0')

Because the return type requires an explicit conversion before being wrapped as a ValueTask<object> to confirm with the EndpointFilterDelegate's signature.

Note: I'm considering this for backport to .NET 8 and .NET 9.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 20, 2024
@captainsafia captainsafia added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdf and removed area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Aug 20, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 20, 2024
@captainsafia captainsafia removed the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 20, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 20, 2024
@captainsafia captainsafia removed the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 20, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 20, 2024
@captainsafia captainsafia merged commit 53ba80b into main Aug 20, 2024
26 checks passed
@captainsafia captainsafia deleted the endpoint-filter-return-type-fix branch August 20, 2024 23:51
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Aug 20, 2024
@captainsafia
Copy link
Member Author

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/aspnetcore/actions/runs/10839386689

Copy link
Contributor

@captainsafia backporting to release/8.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add explicit conversion for value-type returning handlers with filters
Using index info to reconstruct a base tree...
M	src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Http/Http.Extensions/src/RequestDelegateFactory.cs
CONFLICT (content): Merge conflict in src/Http/Http.Extensions/src/RequestDelegateFactory.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 Add explicit conversion for value-type returning handlers with filters
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@captainsafia an error occurred while backporting to release/8.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

@captainsafia
Copy link
Member Author

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/aspnetcore/actions/runs/10945223628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-rdf
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants