Skip to content

[area-Tools-ILLink]: dotnet publish crashing when using PublishTrimmed option #109536

@riku76

Description

@riku76

Description

When trying to run do "dotnet publish --configuration Release --output publish\x --self-contained true" for my project I'm getting this:dotnet.zip

Attached a mini dump without heap, because apparently the mini dump with heap is too large for Github. I can provide dump with heap any time if needed.

ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [C:\git2\History\work\MyProject.csproj]
  Fatal error in IL Linker
  Unhandled exception. System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
     at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
     at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
     at System.String.Format(String format, Object[] args)
     at ILLink.Shared.DiagnosticString.GetMessage(String[] args)
     at Mono.Linker.MessageContainer..ctor(MessageCategory category, DiagnosticId id, String subcategory, Nullable`1 origin, String[] args)
     at Mono.Linker.MessageContainer.CreateWarningMessageContainer(LinkContext context, MessageOrigin origin, DiagnosticId id, WarnVersion version, String subcategory, String[] args)
     at Mono.Linker.MessageContainer.CreateWarningMessage(LinkContext context, MessageOrigin origin, DiagnosticId id, WarnVersion version, String[] args)
     at Mono.Linker.LinkContext.LogWarning(MessageOrigin origin, DiagnosticId id, String[] args)
     at ILLink.Shared.TrimAnalysis.DiagnosticContext.AddDiagnostic(DiagnosticId id, String[] args)
     at ILLink.Shared.TrimAnalysis.DiagnosticContext.AddDiagnostic(DiagnosticId id, ValueWithDynamicallyAccessedMembers actualValue, ValueWithDynamicallyAccessedMembers expectedAnnotationsValue, String[] args)
     at ILLink.Shared.TrimAnalysis.RequireDynamicallyAccessedMembersAction.Invoke(ValueSet`1& value, ValueWithDynamicallyAccessedMembers targetValue)
     at ILLink.Shared.TrimAnalysis.HandleCallAction.Invoke(MethodProxy calledMethod, ValueSet`1 instanceValue, IReadOnlyList`1 argumentValues, IntrinsicId intrinsicId, ValueSet`1& methodReturnValue)
     at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.HandleCall(Instruction operation, MethodReference calledMethod, ValueSet`1 instanceValue, ImmutableArray`1 argumentValues, DiagnosticContext diagnosticContext, ReflectionMarker reflectionMarker, LinkContext context, MarkSt
  ep markStep, ValueSet`1& methodReturnValue)
     at Mono.Linker.Dataflow.TrimAnalysisMethodCallPattern.MarkAndProduceDiagnostics(ReflectionMarker reflectionMarker, MarkStep markStep, LinkContext context)
     at Mono.Linker.Dataflow.TrimAnalysisPatternStore.MarkAndProduceDiagnostics(ReflectionMarker reflectionMarker, MarkStep markStep)
     at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.InterproceduralScan(MethodIL methodIL)
     at Mono.Linker.Steps.MarkStep.MarkReflectionLikeDependencies(MethodIL methodIL, Boolean requiresReflectionMethodBodyScanner)
     at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
     at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, MessageOrigin& origin)
     at Mono.Linker.Steps.MarkStep.ProcessQueue()
     at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
     at Mono.Linker.Steps.MarkStep.Process()
     at Mono.Linker.Steps.MarkStep.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)

Reproduction Steps

I can repro every time by just running the "dotnet publish --configuration Release --output publish\x --self-contained true". I'd rather not share my full code. If you are not able to figure it out from the dump / call stack we can see if I can do something to help you further.

Expected behavior

Not crashing

Actual behavior

Crashing

Regression?

Unknown.

Known Workarounds

No known workaround.

Configuration

Latest .NET 8, Windows 11 23H2 (Build 22631.4317), x64. Not tested on other platforms.

Other information

As call stack shows it is failing in your logging code. I tried to disable logging by the command line options, but it did not help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLink.NET linker development as well as trimming analyzersin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions