Skip to content

RDF throws exception for handler with struct parameter and filters #49730

@captainsafia

Description

@captainsafia

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

RDF generates buggy code for endpoints with a:

  • struct parameter type
  • endpoint filter
  • null value for the parameter
System.NullReferenceException
Object reference not set to an instance of an object.
   at lambda_method111(Closure, Object, HttpContext, Object[])
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass99_0.<<HandleRequestBodyAndCompileRequestDelegate>b__0>d.MoveNext() in /Users/captainsafia/repos/2-aspnetcore/src/Http/Http.Extensions/src/RequestDelegateFactory.cs:line 1198

Expected Behavior

Invoking request delegate should not produce an exception.

Steps To Reproduce

var app = WebApplication.Create();

app.MapGet("/struct-with-filter", (BindableStructWithNullReturn param) => "Hello world!")
    .AddEndpointFilter((c, n) => n(c));

app.Run();

public struct BindableStructWithNullReturn
{
    public static async ValueTask<BindableStructWithNullReturn?> BindAsync(HttpContext httpContext, ParameterInfo parameter)
    {
        await Task.CompletedTask;
        return null;
    }
}

Exceptions (if any)

No response

.NET Version

8.0.100-preview.7.23360.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdf

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions