-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
SwaggerUIMiddleware
is broken when used with .NET Native AOT
#2550
Comments
Yes, this also happened to us for a trimmed (copyused) application, whereas in .NET 6 this was not an issue. |
We have been paying attention to this issue for some time. I think this is an easy problem to solve. |
.NET 8 preview 3 has added a Native AOT template for Web APIs ( See: https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-8-preview-3/ |
.NET 8 is nearing release. Wondering if this was considered for an upcoming release |
Seems that this is related to dotnet/runtime#92345, and the workaround is adding It is recommended to switch source-generated context, however it would be enough to explicitly enable reflection-based serialization - https://learn.microsoft.com/en-us/dotnet/core/compatibility/serialization/7.0/reflection-fallback#use-a-custom-contract-resolver. .NET 8 RC1 has already been released, is there any plan to not break builds with trimming enabled? |
I think the The reflection based resolver might still randomly fail when trimming is enabled and I believe it's guaranteed to fail when using Native AOT. So you just end up with a Swashbuckle endpoint that might or might not work after every change in your code or update in the .NET compiler. I've switched to building an OpenAPI spec file using Swashbackle and not using Swashbuckle in the Release build configuration. See: https://medium.com/@mimme/generate-open-api-specification-for-asp-net-core-projects-on-build-c5789d435ffc (the only thing I did different from the medium article was using a seperate |
@quality-leftovers And how do you handle the Swagger UI? Currently the exception happens in the |
Any updates on this topic? .NET 8 releases next week and we would love to use swagger UI. |
Still, we don't have it, is there any update? |
Disclaimer: I am NOT a contributor to this repo |
Any updates on this ? |
I would also love a fix for this. |
Please just add the code generated serializers for the net8 publication of the package to make sure it is trimming and AOT compatible. |
If it's a dangerous change, can we maybe have something like "6.6.0-beta1" nuget where it's included? |
Reflection based serialization is disabled when running the API outside of tests, see domaindrivendev/Swashbuckle.AspNetCore#2550
I get the impression the repo is currently not being maintained. @VMelnalksnis Maybe I was uncleear. I'm not using swagger UI in the release version anymore. I'm just generating an OpenAPI yaml now. In
and in the
|
Can you guys test if DotSwashbuckle solves the issue? Its for .NET 8+ only |
Any updates? this is a blocker btw |
We can look to address this once #2792 is implemented. |
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves domaindrivendev#2550.
Add support for using SwaggerUI with native AoT. SwaggerGen still does not support native AoT, though it happens to work for simple cases. Resolves #2550.
A .NET 7 app can be published as a native executable by setting
<PublishAot>true</PublishAot>
in the csproj.I noticed in my test app that the Swagger UI middleware is broken when native AOT is enabled.
The problem is here:
Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs
Lines 121 to 131 in eede471
JsonSerializer.Serialize
internally attempts to generate dynamic code which isn't compatible with native AOT. It throws an error, and a 500 response is returned to the browser.A fix could be to update these serializer calls to use System.Text.Json source gen - https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/. There are other serializer usages in Swashbuckle that you should test out.
The text was updated successfully, but these errors were encountered: