Skip to content

Generated instance hooks emit IL2075 during Native AOT publishing #7430

Open

Description

@thomhurst

Summary

Native AOT publishing emits IL2075 warnings from generated instance hooks. The generated code calls GetMethod on an instance's GetType() without preserving the reflected method requirements. Users need hook methods retained reliably under trimming and actionable publish diagnostics.

Reproduction

At commit 411189a, run dotnet publish tests/TUnit.TestProject -c Release -f net10.0 -p:Aot=true --use-current-runtime.

The generated HookMetadataGenerator output for GenericHooks.Setup and Bugs._1603.GrandParentTests.SetupBase emits IL2075: Object.GetType() does not satisfy the PublicMethods and NonPublicMethods requirements of Type.GetMethod(String, BindingFlags).

Expected and actual

Generated instance hooks should retain required methods without IL2075 warnings. Publishing succeeds but reports these warnings across multiple generated hook methods. Please correct the generated reflection flow or its preservation annotations.

Environment

.NET SDK 10.0.403, Native AOT compiler 10.0.14, macOS arm64. Observed while validating #7424; the hook generator is unchanged by that PR.

Activity

  1. added
    bugSomething isn't working
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 3, 2026
  2. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    Audited against main d87516cb9c: HookMetadataGenerator.GenerateReflectionBasedInvocation still emits instance.GetType() followed by GetMethod (lines 791–792). The reported reflection flow remains; no closing PR was found. Keep open for the AOT preservation fix and publish validation.

  3. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    Reproduced the generated-hook IL2075 warnings while validating #7476 at e167fcf with SDK 10.0.403 / macOS arm64: dotnet publish tests/TUnit.TestProject -c Release -p:Aot=true --use-current-runtime -f net10.0. Publishing succeeds; GenericHooks and Bugs._2935.GenericTests<T> generated instance hook bodies still warn about GetType() followed by GetMethod(String, BindingFlags). Targeted Native AOT tests pass. This remains separate from the row-scope cleanup change.

  4. thomhurst commented on Nov 4, 2026

    @thomhurst
    OwnerAuthor

    Reproduced while validating #7224 on main 515f198 plus its inference fix, with SDK 10.0.403 on macOS arm64: dotnet publish tests/TUnit.TestProject -c Release -p:Aot=true --use-current-runtime -f net10.0 reports IL2075 in generated instance hooks, including GenericHooks.Before and After. No reflection inference warnings appeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions