DapperLib / DapperAOT

Build time tools in the flavor of Dapper
Other
349 stars 19 forks source link

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

Closed joaofbantunes closed 8 months ago

joaofbantunes commented 8 months ago

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?

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 commented 8 months ago

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

mgravell commented 8 months ago

Investigating, thanks

mgravell commented 8 months ago

tracking via #87

mgravell commented 8 months ago

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

joaofbantunes commented 8 months ago

Just tested it: everything working as expected.

Thanks!