dotnet / linker

387 stars 134 forks source link

IL1012: InvalidCastException: Unable to cast object of type 'Mono.Cecil.FieldReference' to type 'Mono.Cecil.MethodReference'. #3199

Closed bannus closed 8 months ago

bannus commented 1 year ago

I'm seeing the following error when trying to build a MAUI app for net7.0-android.

ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://github.com/dotnet/linker/issues [D:\a\_work\1\s\Test\TestApp\TestApp.csproj::TargetFramework=net7.0-android]
  Fatal error in IL Linker
  Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Mono.Cecil.FieldReference' to type 'Mono.Cecil.MethodReference'.
     at Mono.Cecil.MetadataReader.ReadCustomAttributeRange(Range range, Collection`1 custom_attributes)
     at Mono.Cecil.MetadataReader.ReadCustomAttributes(ICustomAttributeProvider owner)
     at Mono.Cecil.Mixin.<>c.<GetCustomAttributes>b__13_0(ICustomAttributeProvider provider, MetadataReader reader)
     at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
     at Mono.Cecil.Mixin.GetCustomAttributes(ICustomAttributeProvider self, Collection`1& variable, ModuleDefinition module)
     at Mono.Cecil.FieldDefinition.get_CustomAttributes()
     at Microsoft.Android.Sdk.ILLink.ApplyPreserveAttribute.GetPreserveAttributes(ICustomAttributeProvider provider) in /Users/runner/work/1/s/xamarin-android/src/Microsoft.Android.Sdk.ILLink/ApplyPreserveAttribute.cs:line 143
     at Microsoft.Android.Sdk.ILLink.ApplyPreserveAttribute.ProcessField(FieldDefinition field) in /Users/runner/work/1/s/xamarin-android/src/Microsoft.Android.Sdk.ILLink/ApplyPreserveAttribute.cs:line 38
     at Mono.Linker.Steps.MarkSubStepsDispatcher.DispatchField(FieldDefinition field)
     at Mono.Linker.Steps.MarkSubStepsDispatcher.BrowseTypes(Collection`1 types)
     at Mono.Linker.Steps.MarkSubStepsDispatcher.BrowseTypes(Collection`1 types)
     at Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly, DependencyInfo reason)
     at Mono.Linker.Steps.MarkStep.MarkModule(ModuleDefinition module, DependencyInfo reason)
     at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
     at Mono.Linker.Steps.MarkStep.ProcessMarkedPending()
     at Mono.Linker.Steps.MarkStep.Initialize()
     at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
     at Mono.Linker.Pipeline.Process(LinkContext context)
marek-safar commented 1 year ago

This looks like some interesting mix of metadata. Do you have sample that we can use to reproduce the issue?

Archit-Pikle commented 8 months ago

We're not able to repro this anymore