Skip to content

AOT analysis warning when using enums or arrays as parameters #3321

@PhilippNaused

Description

@PhilippNaused

Repro steps:
Build this with dotnet publish --use-current-runtime -t:Rebuild:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <ImplicitUsings>enable</ImplicitUsings>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <PublishAot>true</PublishAot>
    <TrimmerSingleWarn>false</TrimmerSingleWarn>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="TUnit" Version="0.67.4" />
  </ItemGroup>
</Project>
enum Enum1
{
    Value1,
    Value2
}

class Tests
{
    [Test]
    [Arguments(Enum1.Value1)]
    public async Task TestMethod(Enum1 i)
    {
        await Assert.That(i).IsDefined();
    }

    [Test]
    [Arguments(new int[] { 1, 2, 3 })]
    public async Task TestMethod2(int[] i)
    {
        await Assert.That(i).HasCount(3);
    }
}

Results in these warnings:

AOT analysis warning IL3050: Using member 'System.Array.CreateInstance(Type,Int32)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available.
AOT analysis warning IL3050: Using member 'System.Array.CreateInstance(Type,Int32[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available.
AOT analysis warning IL3050: Using member 'System.Array.CreateInstance(Type,Int32[],Int32[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available.
AOT analysis warning IL3050: Using member 'System.Array.CreateInstance(Type,Int64[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available.
AOT analysis warning IL3050: Using member 'System.Enum.GetValues(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. It might not be possible to create an array of the enum type at runtime. Use the GetValues<TEnum> overload or the GetValuesAsUnderlyingType method instead.

The warnings comes from inside the call to TUnit.Core.Helpers.CastHelper.Cast<T>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions