Skip to content

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

@joaofbantunes

Description

@joaofbantunes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions