Skip to content

Generic test class property metadata emits dynamic getters during Native AOT publishing #7499

Closed

Description

@thomhurst

Summary

Public instance properties on generic test classes generate metadata getters using dynamic. Native AOT publishing consequently reports IL2026 and IL3050 for those getters, even when the test itself uses only statically typed code. Property metadata should be accessible without requiring runtime code generation.

Reproduction

At main commit 374bb7c, src/TUnit.Core.SourceGenerator/Utilities/MetadataGenerationHelper.cs:363 emits o => ((dynamic)o).Property for generic classes. Add this fixture to a test application:

[Arguments("first")]
[Arguments("second")]
public class GenericPropertyTests<T>(T value)
{
    public T Value { get; } = value;

    [Test]
    public void Run() { }
}

Publish with dotnet publish -c Release -p:Aot=true --use-current-runtime -f net10.0 in tests/TUnit.TestProject. The required-property fixture introduced by #7496 also reproduces the warnings.

Expected and actual

Expected: metadata getters for a closed generic test class use an AOT-compatible access path.

Actual: generated property getter delegates call Microsoft.CSharp.RuntimeBinder.Binder.GetMember and CallSite.Create, reporting IL2026 and IL3050 because dynamic requires runtime code generation.

Environment

.NET SDK 10.0.403; net10.0; macOS arm64. Confirmed the dynamic getter emission remains on origin/main.

Please generate AOT-compatible getters for generic test class property metadata.

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 workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions