Skip to content

[area-Tools-ILLink]: Trimmer warnings crash the build #129562

Closed

Description

@smoogipoo

Description

Hi!

We're migrating our iOS project from .NET 8 to .NET 10 and we're seeing a lot of trimmer warnings. Of course we should aim to get this down to 0, but our projects work with .NET 8 so we're hoping this to be a simple upgrade for now. However, we're encountering an error when building the project:

ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink
    Fatal error in IL Linker
    Unhandled exception. System.InvalidOperationException: Sequence contains no elements
       at System.Linq.ThrowHelper.ThrowNoElementsException()
       at System.Linq.Enumerable.Last[TSource](IEnumerable`1 source)
       at Mono.Linker.MessageOrigin.ToString()
       at Mono.Linker.MessageContainer.ToMSBuildString()
       at Mono.Linker.LinkContext.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.FlushCachedWarnings()
       at Mono.Linker.Steps.ProcessWarningsStep.Process()
       at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
       at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
       at Mono.Linker.Pipeline.Process(LinkContext context)
       at Mono.Linker.Driver.Run(ILogger customLogger)
       at Mono.Linker.Driver.Main(String[] args)
    /Users/smgi/.nuget/packages/microsoft.net.illink.tasks/10.0.8/build/Microsoft.NET.ILLink.targets(103,5): error NETSDK1144: Optimizing assemblies for size failed.

It looks like one of the warning messages are breaking the process.

Reproduction Steps

  1. Clone + checkout smoogipoo/osu@1a3eb1c.
  2. Go into the osu.iOS subdirectory.
  3. dotnet workload restore + dotnet build.

Expected behavior

The build to pass, albeit with warnings.

Actual behavior

The build fails with the exception above.

Regression?

This build previously worked in .NET 8.

Known Workarounds

Compiling with /p:SuppressTrimAnalysisWarnings=true fixes the issue.

Configuration

$ dotnet --info
.NET SDK:
 Version:           10.0.300
 Commit:            caa81fa497
 Workload version:  10.0.301.1
 MSBuild version:   18.6.3+caa81fa49

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  26.3
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /Users/smgi/.dotnet/sdk/10.0.300/

.NET workloads installed:
 [ios]
   Installation Source: SDK 10.0.300
   Manifest Version:    26.5.10284/10.0.100
   Manifest Path:       /Users/smgi/.dotnet/sdk-manifests/10.0.100/microsoft.net.sdk.ios/26.5.10284/WorkloadManifest.json
   Install Type:        FileBased

Configured to use workload sets when installing new manifests.

Host:
  Version:      10.0.8
  Architecture: arm64
  Commit:       94ea82652c

.NET SDKs installed:
  8.0.421 [/Users/smgi/.dotnet/sdk]
  10.0.300 [/Users/smgi/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.27 [/Users/smgi/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.8 [/Users/smgi/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.27 [/Users/smgi/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.8 [/Users/smgi/.dotnet/shared/Microsoft.NETCore.App]

Other information

No response

Activity

  1. added
    area-Tools-ILLink
    on Jun 18, 2026
  2. added this to the 11.0.0 milestone on Jun 18, 2026
  3. sbomer commented on Jun 25, 2026

    @sbomer
    Member

    I was able to reproduce and narrow this down.

    The crash happens while ILLink is formatting cached trim warnings, not while performing the trim analysis itself. Specifically, MessageOrigin.ToString() assumes there is at least one PDB sequence point at or before the warning's IL offset:

    method.DebugInformation.SequencePoints
        .Where(s => s.Offset <= offset)?.Last();

    For this repro, there are IL2026 warnings from Realm-woven backlink getters:

    osu.Game.Beatmaps.BeatmapInfo.Scores.get
    osu.Game.Models.RealmFile.Usages.get
    

    Both generated getters call:

    System.Linq.Queryable.AsQueryable(IEnumerable<T>)
    

    The warning origin points at the AsQueryable call at IL offset 41 / 0x29, but the method's first PDB sequence point is at offset 51 / 0x33. That makes the filtered sequence-point set empty, so Last() throws:

    System.InvalidOperationException: Sequence contains no elements
       at Mono.Linker.MessageOrigin.ToString()
       at Mono.Linker.MessageContainer.ToMSBuildString()
       at Mono.Linker.LinkContext.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.FlushCachedWarnings()
    

    Suppressing only IL2026 avoids the crash in the repro, while suppressing the other emitted trim-warning codes does not. SuppressTrimAnalysisWarnings=true works because it prevents these cached trim-analysis warnings from being flushed/formatted.

    Likely fix: make MessageOrigin.ToString() tolerate IL offsets before the first sequence point, e.g. use LastOrDefault() and fall back to method-level/no-source origin or the first non-hidden sequence point instead of assuming a matching sequence point exists.

    This content was created with assistance from AI.

  4. self-assigned this
    on Jun 26, 2026
  5. added a commit that references this issue on Jun 26, 2026
    207ffd1
  6. added a commit that references this issue on Jul 15, 2026
    3a7cb24
  7. locked and limited conversation to collaborators on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions