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

[release/8.0] Add explicit conversion for value-type returning handlers with filters #57966

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Sep 19, 2024

Description

Merged in 10.0: #57428
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.

Customer Impact

Without this bug fix, user applications that contain minimal API endpoints that return value types and use endpoint filters will fail to launch. Viable workarounds exist (for example, wrapping the value return in a Results.Ok), but they are difficult for the typical user to discover.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Scope of impact is limited to minimal APIs + endpoint filters + compile-time code generation.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@captainsafia captainsafia added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdf labels Sep 19, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 8.0.x milestone Sep 19, 2024
@captainsafia captainsafia added the Servicing-consider Shiproom approval is required for the issue label Sep 19, 2024
@captainsafia captainsafia changed the title Add explicit conversion for value-type returning handlers with filters [release/8/0] Add explicit conversion for value-type returning handlers with filters Sep 19, 2024
@captainsafia captainsafia changed the title [release/8/0] Add explicit conversion for value-type returning handlers with filters [release/8.0] Add explicit conversion for value-type returning handlers with filters Sep 19, 2024
@BrennanConroy
Copy link
Member

Does RDG handle this? I did a quick search and wasn't able to find any tests that cover it for RDG

@captainsafia
Copy link
Member Author

Does RDG handle this? I did a quick search and wasn't able to find any tests that cover it for RDG

RDG doesn't have this problem because the compiler will do the conversion implicitly when a value type is passed into the this method.

As for tests, I don't believe we have test coverage for this scenario in RDG but I can add one (or move the tests that we have here to the shared infrastructure).

@captainsafia
Copy link
Member Author

Approved via email.

@captainsafia captainsafia added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Oct 1, 2024
@wtgodbe wtgodbe merged commit aab1413 into release/8.0 Oct 2, 2024
25 checks passed
@wtgodbe wtgodbe deleted the safia/backport-filers-value-type-fix branch October 2, 2024 18:33
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 8.0.x, 8.0.11 Oct 2, 2024
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 feature-rdf Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants