dotnet / dotnet/aspnetcore

RDF throws exception for handler with struct parameter and filters

Open
#49,730 1 comment 0 reactions 0 assignees View on GitHub
area-minimal feature-rdf
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] 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.<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 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.