dotnet / dotnet/aspnetcore

[NativeAOT] Incorrect source generator types when Minimal API endpoint delegate return type is inferred

Open
#56,048 0 comments 0 reactions 0 assignees View on GitHub
area-minimal feature-rdg NativeAOT
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When using an inferred type in the delegate passed to a Minimal API endpoint, the source generator does not generate the correct code.

### Expected Behavior

The source generator should infer the types and generate correct code.

This issue does not occur if the type is explicitly declared.

```csharp
return httpClient.GetFromJsonAsync("https://ipinfo.io/", AppJsonSerializerContext.Default.Response);
```

### Steps To Reproduce

https://github.com/qin-guan/dotnet-minimalapi-source-generator-httpclient-repro

### Exceptions (if any)

_No response_

### .NET Version

9.0.100-preview.4.24267.66

### Anything else?

This also occurs with .NET 8

Please see lines 85 and 102

image

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.