-
Notifications
You must be signed in to change notification settings - Fork 537
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
XARRA7028 AssemblyResolutionException in Android App Release Build #9629
Comments
Can you attach a You should be able to remove |
I have created the logs when execution the publish operation in VS (when the error occurs). |
@uholeschak do you know how to cause this issue in a small sample? My best guess is the code here:
It doesn't setup But what type of code in your app would trigger this problem? We'd probably want to write a test to know it solves the problem and it doesn't return. |
The problem is, that this is really a large application with many NuGet packages. |
I am now getting this error for unknown reasons. Suddenly I can no longer build to Release mode in Android for my project. I believe this happened now after I just updated Visual Studio 2022 in the past few days. Nothing in my project has changed to explain it. I was already on .NET 9 and everything was fine (don't know now what version), but then updating to the most recent version a few days ago seems to have broken it. In any case, @uholeschak thank you so much for sharing your workaround and this thread. I made a Directory.Build.Props in the same folder as my sln file with your text content and I can at least build Release again in Android. So thanks again. I spent hours trying to figure out the problem but got nowhere before I found your thread. Hopefully there will be some more formal solution but for now I can at least verify this worked for me temporarily as well. 👍 |
This could be also cause by an NuGet update. |
I tried building your app locally and I get
I assume there are some additional steps to generate these files? |
Basically you have to compile the binaries with a different tool first, but this is complicated. |
I can repo the issue, I commented out all the EmbeddedResource entires in the csproj. As well as the PostBuild target, and the "patched" targets in Directory.Build.targets. Then did can you do a |
As I have written in the into, the problem only occurs only if you publish the app. |
So I tried
Also tried
and building the following from a clean tree.
Nothing, no errors. I have a PR which might fix the issue (#9803), but we can't merge that until I have a solid way to repo this outside of the IDE. I'll see if I can repo on a Windows VM, because on MacOS it seems fine. |
I did a Output of
|
My conjecture as to what's going on is that something is using a Cecil-based IL rewriter tool as a post-build step "somewhere", that rewriter calls Funnily enough, the relationship between the trimmer and the % dotnet new android
% dotnet build -c Release
% for a in obj/Release/net9.0-android/android-arm64/linked/shrunk/*.dll ; do \
echo "## $a" ; \
monodis --assemblyref $a | grep System.Private.CoreLib ; \
done
## obj/Release/net9.0-android/android-arm64/linked/shrunk/Java.Interop.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/Mono.Android.Runtime.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/Mono.Android.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Console.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Linq.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Private.CoreLib.dll
## obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Runtime.InteropServices.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/System.Runtime.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/_Microsoft.Android.Resource.Designer.dll
Name=System.Private.CoreLib
## obj/Release/net9.0-android/android-arm64/linked/shrunk/net9-android.dll
Name=System.Private.CoreLib which is to say, nearly every trimmed assembly contains a reference to Yet this build is successful. The approach in #9803 should improve matters, but I don't know if it would be a fix. |
…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 ```
When will this be this published? Then I could try again ... |
It should be published as part of .NET 10 Preview 2, sometime in March. |
Android framework version
net9.0-android
Affected platform version
VS2022 17.12.3
Description
When building and publishing an Android app in Release mode the build always fails with the following error message, but the missing
System.Private.CoreLib Version=9.0.0.0
is present.The problem is the MSBuild target
_RemoveRegisterAttribute
, which is run after AOT. Is seems that in this state the assembly dependencies are not accessible any more.Steps to Reproduce
Did you find any workaround?
Disable the _RemoveRegisterAttribute target by setting in
Directory.Build.Props:
Relevant log output
The text was updated successfully, but these errors were encountered: