Skip to content
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

[NativeAOT] Publishing with NativeAOT and trimming results in broken code #58509

Open
1 task done
AlexMacocian opened this issue Oct 18, 2024 · 1 comment
Open
1 task done
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdg NativeAOT

Comments

@AlexMacocian
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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

app.MapPost("route", async (someparams) => 
{
    return await someMethod();
});

should return a json generated by someMethod(), not a json that looks like

{
    "result": {},
    "asyncState": null,
    "creationOptions": 0,
    "exception": null,
    "id": 2,
    "isCanceled": false,
    "isCompleted": true,
    "isCompletedSuccessfully": true,
    "isFaulted": false,
    "status": 5
}

Steps To Reproduce

Here's a link to the repo:
https://github.com/AlexMacocian/Badge
Run docker compose up in Badge subdirectory.

  • In Program.cs:

    • Uncomment .UseRoutes() and comment out UseRoutes2(app)
    • Build and run the docker image
    • Do an empty POST request to http://localhost/api/oauth/token or a GET request to http://localhost/api/oauth/.well-known/jwks.json
    • Observe the serialized Task response
  • Go back to Program.cs

    • Comment .UseRoutes() and uncomment UseRoutes2(app)
    • Build and run the docker image
    • Do an empty POST request to http://localhost/api/oauth/token or a GET request to http://localhost/api/oauth/.well-known/jwks.json
    • Observe the proper json responses
  • Finally, compare generated UseRoutes() extension method with UseRoutes2() method that is copied in Program.cs. UseRoutes2() is a copy of UseRoutes(), 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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Oct 18, 2024
@AlexMacocian
Copy link
Author

Another thing to note, if I copy the generated code from UseRoutes() inside Program.cs, call it UseRoutes2() and call that one instead, I no longer have the issue described above.

This really looks like something that has to do with the generated code is compiled. But it makes no sense that the same code would result in different functionality, if copied inside the Program.cs

@captainsafia captainsafia added feature-rdg area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdg NativeAOT
Projects
None yet
Development

No branches or pull requests

2 participants