Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
riku76 opened this issue Nov 5, 2024 · 3 comments · Fixed by #110229 or #110330
Closed

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

riku76 opened this issue Nov 5, 2024 · 3 comments · Fixed by #110229 or #110330
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@riku76
Copy link

riku76 commented Nov 5, 2024

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 5, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 5, 2024
@huoyaoyuan huoyaoyuan added area-Tools-ILLink .NET linker development as well as trimming analyzers and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 5, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

@sbomer sbomer added this to the 10.0.0 milestone Nov 5, 2024
@sbomer sbomer removed the untriaged New issue has not been triaged by the area owner label Nov 5, 2024
@vitek-karas
Copy link
Member

It's likely a dupe of #93800 which has the same callstack - as part of that investigation I looked around the other warnings and didn't see a similar problem in any other case.

@riku76
Copy link
Author

riku76 commented Nov 8, 2024

I can see that the possible dupe has been open over one year already. It is generally a good idea to wrap your logging code inside a try-catch to make issues in logging non-fatal, so could you consider doing at least that while waiting for the actual fix?

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Nov 27, 2024
jtschuster added a commit that referenced this issue Jan 6, 2025
…ormatting diagnostics (#110229)

Fixes #109536

See #93800 for more context.

When a NullableValue is the source of an assignment, we consider use the TypeArgumentTargetsX diagnostic since the underlying value is a generic argument, but use the source of the generic argument for diagnostics. This leads to some confusing warning messages, and sometimes crashes in formatting the diagnostics. Ideally, we would want to unwrap the NullableValues and use the UnderlyingTypeValue as the source, but this would be a breaking change for the situations that don't crash.

FieldValue and MethodReturnValue only provide 1 diagnostic arguments, but the diagnostics for TypeArgumentTargetsX expects 2 arguments from the source. This caused crashes when the situation was encountered. Since they didn't work before at all, this won't be a breaking change to provide the correct warning here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers in-pr There is an active PR which will close this issue when it is merged
Projects
Status: No status
4 participants