Skip to content

[NativeAOT] dotnet publish -c Release -v diag hangs at IlcCompile with <TrimmerRootAssembly Include="Npgsql"/> #115267

@mmahdium

Description

@mmahdium

Description

After enabling Native AOT (<PublishAot>true</PublishAot>) and adding a root-assembly hint for Npgsql, the publish process hangs indefinitely during the IlcCompile step, consuming increasing amounts of memory without completing. Removing the <TrimmerRootAssembly Include="Npgsql"/> line allows publish to succeed, but the resulting binary misbehaves at runtime due to trimming of Npgsql assembly.

Reproduction Steps

  1. Create a new ASP NET Core Web API

    dotnet new webapi -n AotHangTest
    cd AotHangTest
  2. Add FreeSql, its QuestDB provider and JWT Bearer

    dotnet add package FreeSql.Repository --version 3.5.204
    dotnet add package FreeSql.Provider.QuestDb --version 3.5.204
  3. Edit AotHangTest.csproj

    <PropertyGroup>
      <TargetFramework>net9.0</TargetFramework>
      <PublishAot>true</PublishAot>
      <InvariantGlobalization>true</InvariantGlobalization>
      <!-- other settings as needed -->
    </PropertyGroup>
    
    <ItemGroup>
      <!-- ensure Npgsql is rooted so it isn’t trimmed away -->
      <TrimmerRootAssembly Include="Npgsql" />
    </ItemGroup>
  4. Publish with diagnostics

    dotnet publish -c Release -v diag

    — observe that the build hangs indefinitely at the IlcCompile step (memory usage climbs without completing).

Expected behavior

The publish step should complete successfully, producing a working Native AOT binary that includes all required Npgsql functionality (no runtime trimming errors).

Actual behavior

  • The IlcCompile task never completes.
  • The native-AOT compiler process (ilc) memory usage grows (observed up to ~2.5 GiB for a small project) and never returns control to MSBuild.

Regression?

  • A different project using FreeSql + MySQL provider with <TrimmerRootAssembly Include="MySql.Data"/> builds and publishes with no hangs or excessive memory use.
  • Suspect an interaction between the Npgsql assembly and the NativeAOT compiler’s trimming logic.
  • This behavior is only observed in dotnet publish and does not affect the dotnet run command.

Known Workarounds

  • Remove the <TrimmerRootAssembly Include="Npgsql" /> entry so the publish completes—but note this causes Npgsql types to be trimmed away at runtime, leading to failures when the app tries to use the database.

Configuration

  • .NET SDK version: 9.0.203
  • OS: Arch Linux - 6.14.3-arch1-1 x86_64
  • Project configuration:
<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net9.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <RootNamespace>*****</RootNamespace>
        <InvariantGlobalization>true</InvariantGlobalization>
        <PublishAot>true</PublishAot>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="FreeSql.Provider.QuestDb" Version="3.5.204"/>
        <PackageReference Include="FreeSql.Repository" Version="3.5.204"/>
        <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.4"/>
    </ItemGroup>

    <ItemGroup>
        <Content Include="..\.dockerignore">
            <Link>.dockerignore</Link>
        </Content>
        <TrimmerRootAssembly Include="Npgsql"/>
    </ItemGroup>

</Project>

Other information

Because the hang at IlcCompile causes excessive memory usage and never completes—even on a minimal project—I’ve chosen to file this issue in the dotnet/runtime repository rather than in the FreeSql or Npgsql repos. The Native AOT compiler and trimmer are part of the runtime toolchain, and this appears to be a problem in how the runtime handles rooted assemblies during AOT compilation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions