Skip to content

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 19, 2024

Description

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

@ghost ghost added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Sep 19, 2024
@captainsafia captainsafia added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdf Servicing-consider Shiproom approval is required for the issue and removed area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Sep 19, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2024
@captainsafia
Copy link
Member

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
@captainsafia
Copy link
Member

/azp run

@dotnet-policy-service dotnet-policy-service bot removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 1, 2024
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@captainsafia
Copy link
Member

captainsafia commented Oct 1, 2024

@BrennanConroy @amcasey Can I get a review here? This is the same as the changeset in the other branches.

This was referenced Aug 18, 2025
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.

4 participants