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

Source generation seemingly not working when using minimal APIs and top level statements #86

Closed
joaofbantunes opened this issue Nov 18, 2023 · 5 comments

Comments

@joaofbantunes
Copy link

joaofbantunes commented Nov 18, 2023

Describe the bug

When building a sample application using minimal APIs and top level statements (sample linked below), it seems like the source generation isn't working as expected. Even though adding the [module:DapperAot], compiling produces Warning DAP005 : 1 candidate Dapper methods detected, but none have Dapper.AOT enabled, and running the application results in the expected errors, due to not being able to use dynamic code generation under Native AOT.

If I move the code to a static class and map the endpoint, then the warning disappears and everything works as expected.

I imagine this isn't a very relevant issue, as in non-sample code, it's unlikely to have queries in top level statements, but just in case it's an unknown issue (or maybe I'm using it wrong), I thought of reporting.

Where are you seeing this?

  • what Dapper/Dapper.StrongName version? 2.1.21
  • what Dapper.AOT/Dapper.Advisor version? 1.0.16
  • if relevant: what database backend? Npgsql 8.0.0-rc.2
  • dotnet --version: 8.0.100

To Reproduce
Sample code
Note: out of the box this code works, because the direct route to code is commented out and replaced with a static class, but reverting things, we can see the reported issue.

Expected behavior

Source generation works regardless of where the queries are used.

However, if supporting this scenario is not worth the effort, maybe include it as a known limitation in the docs.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@davidivkovic
Copy link

Can confirm reproduction, System.PlatformNotSupportedException: Dynamic code generation is not supported on this platform. is thrown.

@mgravell
Copy link
Member

Investigating, thanks

mgravell added a commit that referenced this issue Nov 20, 2023
@mgravell
Copy link
Member

tracking via #87

@mgravell
Copy link
Member

https://github.com/DapperLib/DapperAOT/releases/tag/1.0.23

@joaofbantunes
Copy link
Author

Just tested it: everything working as expected.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants