Skip to content

Suppress trim and AOT diagnostics in Dapper fallback paths - #2233

Open
JamesNK wants to merge 1 commit into
DapperLib:mainfrom
JamesNK:fix/2232-dapper-aot-diagnostics
Open

JamesNK wants to merge 1 commit into
DapperLib:mainfrom
JamesNK:fix/2232-dapper-aot-diagnostics

Conversation

@JamesNK

@JamesNK JamesNK commented Sep 14, 2026

Copy link
Copy Markdown

Fixes #2232.

Summary

Add method-level UnconditionalSuppressMessage attributes for the reflection, runtime generic construction, and DynamicMethod paths reported by the Dapper.AOT-enabled Native AOT dashboard application:

  • DefaultTypeMap property/field discovery and inherited property setter lookup (IL2070, IL2075).
  • StructuredHelper.CreateFor provider-specific structured parameters (IL2070, IL3050).
  • SqlMapper.AddTypeHandlerCore and LookupDbType runtime generic construction (IL3050).
  • SqlMapper.CreateParamInfoGenerator runtime parameter-object generation (IL2075, IL3050).
  • TypeExtensions.GetPublicInstanceMethod framework method lookup (IL2070).

Includes an internal compatibility definition of UnconditionalSuppressMessageAttribute for the legacy target frameworks. No public signatures or execution paths change.

This is a diagnostic-suppression change, not an AOT-safe rewrite: it does not preserve reflected members, root arbitrary generic instantiations, or remove the fallback implementations from the reachable graph. Unsupported fallback usage remains unsupported.

Validation

  • dotnet build .\Dapper\Dapper.csproj --no-restore succeeded for net461, netstandard2.0, net8.0, and net10.0.
  • The standalone Dapper.AOT/SQLite sample below published for win-x64 with Native AOT and zero Dapper IL diagnostics. The check included all Dapper IL warning IDs, not just the three reported in the issue.
  • Running the published native executable printed 42.
  • SDK used: 11.0.100-rc.1.26425.128; sample target framework: net10.0.
  • The sample restore/publish also reported NU1903 for transitive SQLitePCLRaw.lib.e_sqlite3 2.1.11 (advisory). This was separate from the Dapper IL diagnostics; these are the exact package versions tested, not a dependency-version recommendation.
  • Full test suite attempted with dotnet test .\tests\Dapper.Tests\Dapper.Tests.csproj --no-restore --framework net10.0: 66 passed, 30 skipped, 704 failed. SQL Server connection failures were reported because the required database instance was unavailable, so the full suite is not validated as passing.
  • No source diagnostics were reported for the changed files. CRLF-aware git diff --check passed.

The standalone sample was created outside the repository and is included below rather than added to the solution. It validates the scalar DynamicParameters scenario; the full Aspire dashboard was not republished for this patch.

DapperIssue2232.csproj

This is the project used for validation. Adjust the absolute ProjectReference to point to the Dapper checkout being tested.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <PublishAot>true</PublishAot>
    <TrimmerSingleWarn>false</TrimmerSingleWarn>
    <InterceptorsNamespaces>$(InterceptorsNamespaces);Dapper.AOT</InterceptorsNamespaces>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="C:\Development\Source\Dapper\Dapper\Dapper.csproj" />
    <PackageReference Include="Dapper.AOT" Version="1.1.0" />
    <PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.8" />
  </ItemGroup>
</Project>

Program.cs

using System;
using Dapper;
using Microsoft.Data.Sqlite;

[module: DapperAot]

using var connection = new SqliteConnection("Data Source=:memory:");
connection.Open();

var parameters = new DynamicParameters();
parameters.Add("Value", 42);
Console.WriteLine(connection.QuerySingle<int>("select @Value", parameters));

Publish And Run

Run from the standalone sample directory with the Windows Native AOT build prerequisites installed:

dotnet publish .\DapperIssue2232.csproj -c Release -r win-x64 --self-contained true -p:ContinuousIntegrationBuild=false
.\bin\Release\net10.0\win-x64\publish\DapperIssue2232.exe

Observed native executable output:

42

@JamesNK

JamesNK commented Sep 14, 2026

Copy link
Copy Markdown
Author

Vibe coded. Please double check this is good. I'm not very fimilar about how Dapper and Dapper.AOT interact.

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

Successfully merging this pull request may close these issues.

Dapper.AOT leaves trim-unsafe Dapper reflection paths reachable during Native AOT publish

1 participant