Skip to content

ILC IL3050 False positives when building with PublishAot #98864

Description

@hwoodiwiss

Description

Firstly, sorry for the bad/vague name. I'm not sure what's triggering this.

When building targeting NativeAOT, I have come across a case in which I am hitting what I beleive is a false positive analyzer warning from ILC/ILLink while generating native code.

I'm seeing an analyzer warning:

ILC : AOT analysis warning IL3050: GitHub.Models.PullRequestReview.<GetFieldDeserializers>b__58_0(IParseNode): 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. [R:\source\repos\IL3050FalsePositiveRepro\IL3050FalsePositiveRepro.csproj]

However, I can't see how the referenced method is using System.Enum.GetValues(Type), either directly, nor indireclty.

This is consistent across both SDK 8.0.201 and SDK 9.0.100-preview.1.24101.2

Reproduction Steps

I've created a minimal reproduction here: https://github.com/hwoodiwiss/IL3050FalsePositiveRepro

The behaviour exhibited in the above repo is consistent across methods in Kiota generated APIs that use enums.

Expected behavior

No IL3050 warnings. I can't see anywhere that a method marked with RequiresUnreferencedCode is called in the call chain.

Actual behavior

ILC : AOT analysis warning IL3050 during builds, which now causes build errors when TreatWarningsAsErrors is enabled with the .NET 9 previews.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions