Skip to content

IL206/ IL2070/IL2090 Linker errors when trimming/AOTing around enums #114307

Open
@blowdart

Description

@blowdart

Description

When attempting to run an aot/trimming test program I get unexpected trim analysis errors around enums, and around a suppressed line of code.dotnet

Reproduction Steps

See https://github.com/blowdart/idunno.Bluesky/tree/il2070-2090-issue

Clone and run .\trimTest.ps1

Expected behavior

Code compiles, links (respecting suppressions in JsonOptions.cs) and produces trimmed AOT executable.

Actual behavior

Errors on linking

  idunno.TrimmingTest failed with 5 error(s) (9.5s) → trimming\bin\Release\net8.0\win-x64\idunno.TrimmingTest.dll
    Optimizing assemblies for size. This process might take a while.
    G:\idunno.Bluesky\src\idunno.AtProto\JsonOptions.cs(42,13): Trim analysis error IL2026: idunno.AtProto.JsonOptions.CreateDefaultTypeResolver(): Using member 'System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.DefaultJsonTypeInfoResolver()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
    ILLink : Trim analysis error IL2090: System.Text.Json.Serialization.Converters.EnumConverter<T>.ResolveEnumFields(JsonNamingPolicy): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The generic parameter 'T' of 'System.Text.Json.Serialization.Converters.EnumConverter<T>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    ILLink : Trim analysis error IL2070: System.Text.Json.Serialization.Converters.EnumConverterFactory.Create(Type, EnumConverterOptions, JsonNamingPolicy, JsonSerializerOptions): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Type.MakeGenericType(Type[])'. The parameter 'enumType' of method 'System.Text.Json.Serialization.Converters.EnumConverterFactory.Create(Type, EnumConverterOptions, JsonNamingPolicy, JsonSerializerOptions)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    ILLink : Trim analysis error IL2070: System.Text.Json.Serialization.Converters.NullableConverterFactory.GetNullableConverterType(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Type.MakeGenericType(Type[])'. The parameter 'valueTypeToConvert' of method 'System.Text.Json.Serialization.Converters.NullableConverterFactory.GetNullableConverterType(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    G:\Users\BarryDorrans\.nuget\packages\microsoft.net.illink.tasks\8.0.14\build\Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed.

Build failed with 5 error(s) and 1 warning(s) in 14.1s

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
 Version:           9.0.201
 Commit:            071aaccdc2
 Workload version:  9.0.200-manifests.5c4e24dc
 MSBuild version:   17.13.13+1c2026462

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.201\

Host:
  Version:      9.0.3
  Architecture: x64
  Commit:       831d23e561

.NET SDKs installed:
  7.0.302 [C:\Program Files\dotnet\sdk]
  9.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Other information

@eiriktsarpalis Here's the pared back repo :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions