Skip to content

Build error when using LinkMode=copyused, but LinkMode=link or no-trimming works #6625

Closed

Description

@lauxjpn

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

.NET 6.0.100

Description

I have a .NET 6 android app.
When using LinkMode=link or PublishTrimmed=false the app builds fine.

When using LinkMode=copyused I get the following exception at build time:

Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.101-preview.11.117\tools\Xamarin.Android.Common.targets(1375,3): Error XALNS7028 : System.IO.FileNotFoundException: Could not load assembly 'Xamarin.AndroidX.Transition, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Xamarin.AndroidX.Transition.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 245
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 191
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/cecil/Mono.Cecil/MetadataResolver.cs:line 110
   at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/cecil/Mono.Cecil/ModuleDefinition.cs:line 762
   at Mono.Cecil.TypeReference.Resolve() in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/cecil/Mono.Cecil/TypeReference.cs:line 278
   at Java.Interop.Tools.Cecil.TypeDefinitionCache.Resolve(TypeReference typeReference) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionCache.cs:line 20
   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.GetTypeAndBaseTypes(TypeDefinition type, IMetadataResolver resolver)+MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 40
   at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName, IMetadataResolver resolver) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 94
   at MonoDroid.Tuner.FixAbstractMethodsStep.FixAbstractMethods(AssemblyDefinition assembly)
   at Xamarin.Android.Tasks.LinkAssembliesNoShrink.RunTask()
   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 22

The library Xamarin.AndroidX.Transition is being transitively referenced with version 1.4.1.3. Explicitly referencing the assembly leads to the same exception.

I can't say for sure, whether this is an issue with the AndroidX binding or the build task, but I was under the impression that using LinkMode=copyused is the safer trimming mode and so I consider this inconsistency at build time unexpected.

Steps to Reproduce

See description.

Did you find any workaround?

Only not to use LinkMode=copyused.

Relevant log output

See description.

Activity

  1. added
    Area: App+Library Build
    needs-triage
    on Jan 7, 2022
  2. removed
    needs-triage
    on Apr 13, 2022
  3. added this to the .NET 6 milestone on Apr 13, 2022
  4. modified the milestones: .NET 6, .NET 7 on Apr 18, 2022
  5. modified the milestones: .NET 7, .NET 8 on Aug 29, 2022
  6. added
    bug
    Area: Trimming
    on Oct 10, 2023
  7. added
    possibly-stale
    on Aug 7, 2026
  8. dotnet-policy-service commented on Aug 7, 2026

    @dotnet-policy-service

    We suspect this issue is stale and no longer relevant. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

  9. dotnet-policy-service commented on Aug 21, 2026

    @dotnet-policy-service

    This issue will now be closed since it had been marked "possibly-stale" but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  10. locked and limited conversation to collaborators on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildArea: Trimmingbugpossibly-stale

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions