[NativeAOT] Publishing with NativeAOT and trimming results in broken code #58509
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
feature-rdg
NativeAOT
Is there an existing issue for this?
Describe the bug
I have a source generator that builds some minimal api from controller classes. The source generator creates an extension method for
WebApplication
which maps all methods from the controllers with the dependencies and parameters of the methods.When running under Debug, the app works fine and returns expected responses.
When building my docker image and publishing the app with NativeAOT and trimming, on certain flows, the API calls return a serialization of the Task object instead of the IResult result from the Task
Expected Behavior
should return a json generated by
someMethod()
, not a json that looks likeSteps To Reproduce
Here's a link to the repo:
https://github.com/AlexMacocian/Badge
Run
docker compose up
inBadge
subdirectory.In
Program.cs:
.UseRoutes()
and comment outUseRoutes2(app)
http://localhost/api/oauth/token
or a GET request tohttp://localhost/api/oauth/.well-known/jwks.json
Go back to
Program.cs
.UseRoutes()
and uncommentUseRoutes2(app)
http://localhost/api/oauth/token
or a GET request tohttp://localhost/api/oauth/.well-known/jwks.json
Finally, compare generated
UseRoutes()
extension method withUseRoutes2()
method that is copied inProgram.cs
.UseRoutes2()
is a copy ofUseRoutes()
, just placed outside of the generated extension and not marked as an extension method. But otherwise, it contains the same code.Exceptions (if any)
No response
.NET Version
.NET SDK: Version: 8.0.403 Commit: c64aa40a71 Workload version: 8.0.400-manifests.18f19b92 MSBuild version: 17.11.9+a69bbaaf5 Runtime Environment: OS Name: debian OS Version: 12 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/8.0.403/ .NET workloads installed: Configured to use loose manifests when installing new manifests. There are no installed workloads to display. Host: Version: 8.0.10 Architecture: x64 Commit: 81cabf2857 .NET SDKs installed: 8.0.403 [/usr/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 8.0.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Anything else?
No response
The text was updated successfully, but these errors were encountered: