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

ILLink : error IL1012 (System.ArgumentException: Value does not fall within the expected range.) #3222

Open
wsficke opened this issue Jul 14, 2023 · 1 comment

Comments

@wsficke
Copy link

wsficke commented Jul 14, 2023

Error below occurs when trimming a proprietary and relatively complex Avalonia UI project. If further information is required for triage analysis, please mention me in discussion to arrange a private conversation.

MSBuild version 17.6.3+07e294721 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  
  ...
  
Optimizing assemblies for size. This process might take a while.
ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://github.com/do
tnet/linker/issues [C:\Users\sficke\source\repos\Winmark.DRS\Winmark.DRS.Frontend\Winmark.DRS.Frontend.csproj]
  Fatal error in IL Linker
  Unhandled exception. System.ArgumentException: Value does not fall within the expected range.
     at Mono.Cecil.MetadataReader.GetMember[TMember](Collection`1 members, MetadataToken token)
     at Mono.Cecil.MetadataReader.GetProperty(TypeDefinition type, MetadataToken token)
     at Mono.Cecil.MetadataReader.ReadMethodSemantics(MethodDefinition method)
     at Mono.Cecil.MetadataReader.ReadAllSemantics(TypeDefinition type)
     at Mono.Cecil.MetadataReader.ReadAllSemantics(MethodDefinition method)
     at Mono.Cecil.MethodDefinition.<>c.<ReadSemantics>b__27_0(MethodDefinition method, MetadataReader reader)
     at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read)
     at Mono.Cecil.MethodDefinition.ReadSemantics()
     at Mono.Cecil.MethodDefinition.get_SemanticsAttributes()
     at Mono.Linker.MethodDefinitionExtensions.IsPropertyMethod(MethodDefinition md)
     at Mono.Linker.MethodDefinitionExtensions.TryGetProperty(MethodDefinition md, PropertyDefinition& property)
     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.Process(LinkContext context)
     at Mono.Linker.Driver.Run(ILogger customLogger)
     at Mono.Linker.Driver.Main(String[] args)
C:\Program Files\dotnet\sdk\7.0.304\Sdks\Microsoft.NET.ILLink.Tasks\build\Microsoft.NET.ILLink.targets(86,5): error NET
SDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to
false. [C:\...\MyProject\MyProject.csproj]```
@vitek-karas
Copy link
Member

The failing method is:
https://github.com/dotnet/cecil/blob/1a6a83a8f50e1119f1007b1e3c211d3289ba6901/Mono.Cecil/AssemblyReader.cs#L1666-L1667

This can only fail like the above if the member in question can't be found. This would suggest potentially invalid IL, or IL with unresolvable tokens. Specifically this seems to fail because there's a method with a semantics record marking it as getter/setter for a property, but the property token which points to the property the method belongs to can't be resolved to a property on the same type.

Without providing us a repro, you might be able to attach a .NET debugger to the illink process and see what method is being processed when this happens. I would probably do something like:

  • Rerun the publish command which causes the failure with /bl to get msbuild binlog.
  • Open the binlog with https://msbuildlog.com/ viewer
  • Find the failing illink invocation
  • The task illink should have a command line which was executed to run the illink - copy that.
  • Run the command line under a .NET debugger and make it stop on all exceptions. Note that it's likely there will be exceptions before the one from this issue, so you may need to "continue" over those.
  • Once you're stopped on the right exception go up the stack to the MarkStep.ProcessMethod, the first parameter method should be the method in question (very likely the accessor which is problematic).

Once you have the affected method, I would use something like ilspy to open the IL and see if there's something wrong with it. You might also be able to tell where the method came from.

If you're comfortable providing us a repro (privately), please file a VS feedback item. That will let you upload the repro in such a way that only MS employees will see it.

/cc @sbomer @agocke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants