Commit d012fb8
authored
[Xamarin.Android.Build.Tasks] RemoveRegisterAttr IAssemblyResolver (#9803)
Fixes? #9629
In #9629 the customer reports a build failure:
XARRA7028: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
bei Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
bei Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
bei Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
bei Mono.Cecil.TypeReference.Resolve()
bei Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
bei Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
bei Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
bei Mono.Cecil.MetadataBuilder.AddField(FieldDefinition field)
bei Mono.Cecil.MetadataBuilder.AddFields(TypeDefinition type)
bei Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
bei Mono.Cecil.MetadataBuilder.AddTypes()
bei Mono.Cecil.MetadataBuilder.BuildTypes()
bei Mono.Cecil.MetadataBuilder.BuildModule()
bei Mono.Cecil.MetadataBuilder.BuildMetadata()
bei Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
bei Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
bei Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
bei Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
bei Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
bei Xamarin.Android.Tasks.RemoveRegisterAttribute.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/RemoveRegisterAttribute.cs:Zeile 33.
bei Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:Zeile 25.
We are unable to reproduce this, and the scenario doesn't quite make
sense to us: the `<RemoveRegisterAttribute/>` task operates on post-
trimmed assemblies, *nearly all of which* will contain a reference to
`System.Private.CorLib.dll` [^1]. Why does this work of us (and CI!
and most other customers!) and fail in this instance?
¯\\_(ツ)_/¯
Meanwhile, we do know of a plausible "fix"/"workaround": add the use
of a `DirectoryAssemblyResolver` which contains the directory
containing the assembly we're processing.
The `$(IntermediateOutputPath)android-*/linked/shrunk` should also
contain a `System.Private.CoreLib.dll` [^1], which will allow it to
be resolved, thus avoiding the `AssemblyResolutionException`.
[^1]: Consider:
```
for a in obj/Release/net9.0-android/android-arm64/linked/shrunk/*.dll ; do \
echo "Assembly: $a" ; \
monodis --assemblyref $a | grep System.Private.CoreLib ; \
done
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/Java.Interop.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/Mono.Android.Runtime.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/Mono.Android.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Console.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Linq.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Private.CoreLib.dll
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Runtime.InteropServices.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Runtime.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/_Microsoft.Android.Resource.Designer.dll
Name=System.Private.CoreLib
Assembly: obj/Release/net9.0-android/android-arm64/linked/shrunk/net9-android.dll
Name=System.Private.CoreLib
```1 parent 66ffd38 commit d012fb8
File tree
1 file changed
+6
-2
lines changed- src/Xamarin.Android.Build.Tasks/Tasks
1 file changed
+6
-2
lines changedLines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
0 commit comments