-
Notifications
You must be signed in to change notification settings - Fork 10k
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
SwaggerUI broken by primitive return values + endpoint filters #52128
Comments
Has a fix been found for this? This sample code will fail, but changing the X and Y properties to string will work fine: var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapPost("/addsmallnumbers", (AddRequest request) =>
{
return request.X + request.Y;
}).AddEndpointFilter(async (ctx, next) =>
{
return await next(ctx);
});
app.Run();
public class AddRequest
{
public int X { get; set; } = default;
public int Y { get; set; } = default;
} |
It's still broken as of version 8.0.4. You can work around it by casting as (object), but this will defeat reflection based swagger generation done. |
I just downloaded the lastest .net 8 sdk... I still get this issue.. |
I'll try to take a look at this bug and see if we can slot it in for servicing. In the meantime, you can try seeing if compiling your application using the source generator for minimal APIs will work for you. It doesn't run into the same conversion bug we are seeing here with the Linq expressions we generated.
|
This is fixed now in .NET 10 Preview 1 (we've already branched for .NET 9). .NET 10 preview builds aren't available yet. I'd like to wait until they are, have folks try them out to validate the fix, then backport to 8.0/9.0 once we've confirmed that this fix resolves the issue. |
The issue only occur if the method that return int result has also an endpoint filter, without the filter, it works. |
Thanks for your patience here, everyone! The fix for this has been merged into all release branches and will ship in .NET 8.0.11, 9.0, and 10. |
Is there an existing issue for this?
Describe the bug
A combination of returning primitives from a minimal API delegate and adding an endpoint filter will cause the SwaggerUI page to crash. Primitive return values and endpoint filters do not cause this problem individually. This is in an application targeting .NET Core 7.
Expected Behavior
SwaggerUI page renders.
Steps To Reproduce
app.MapGet("/", () =>
{
return 1;
}).AddEndpointFilter(async (context, nextFilter) => await nextFilter(context));
Exceptions (if any)
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')
.NET Version
8.0.100
Anything else?
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.8d38d0cc
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.100\
.NET workloads installed:
Workload version: 8.0.100-manifests.8d38d0cc
[wasm-tools-net6]
Installation Source: VS 17.8.34309.116
Manifest Version: 8.0.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.net6\8.0.0\WorkloadManifest.json
Install Type: Msi
Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71
.NET SDKs installed:
8.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
The text was updated successfully, but these errors were encountered: