android: ResolveAssemblies task wrongly uses reference assemblies

Steps to Reproduce

  1. Get and Build repro https://github.com/marcominerva/XamarinAndroidIssue

If you instead the build log you will see that

Using "ResolveAssemblies" task from assembly "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Build.Tasks.dll".

has few ...ref/netstandard2.0/... references which is wrong as they should never be used as an input to linker or any post compilation processing

This issue is possibly related to #1154

Expected Behavior

No error during execution.

Actual Behavior

[Mono] Assembly Loader probing location: ‘System.Memory’. [monodroid-assembly] Could not load assembly ‘System.Memory’ during startup registration.

Version Information

Xamarin.Android Version: 8.1.0.25 (Visual Studio Community) Android SDK: /Users/marek/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 6.0 (API level 23) 7.1 (API level 25)

SDK Tools Version: 25.2.5 SDK Platform Tools Version: 25.0.5 SDK Build Tools Version: 25.0.3

Log File

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1500,2): warning : Ignoring /Users/marek/.nuget/packages/system.buffers/4.4.0/ref/netstandard2.0 as it is a Reference Assembly
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1500,2): warning : Ignoring /Users/marek/.nuget/packages/system.memory/4.4.0-preview2-25405-01/ref/netstandard2.0 as it is a Reference Assembly
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1500,2): warning : Ignoring /Users/marek/.nuget/packages/system.runtime.compilerservices.unsafe/4.4.0/ref/netstandard2.0 as it is a Reference Assembly

VS bug #585873

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s a functioning workaround. It’s hacky and ugly but works with minimum fuss. Put this in an XML file and <Import> it in your Android csproj file at the end. It works at least for System.Buffers

<!-- Workaround for https://github.com/xamarin/xamarin-android/issues/1162 -->
<Project>
  <Target Name="ReplaceRefAssemblies" AfterTargets="_ResolveAssemblies">
    <ItemGroup>
      <ResolvedAssembliesFixedWindows Include="@(ResolvedAssemblies->Replace('\ref\','\lib\'))" />
      <ResolvedAssembliesFixedUnix Include="@(ResolvedAssemblies->Replace('/ref/','/lib/'))" />
      <ResolvedAssembliesFixed Include="@(ResolvedAssembliesFixedWindows)" Condition="@(ResolvedAssembliesFixedWindows) != @(ResolvedAssemblies)" />
      <ResolvedAssembliesFixed Include="@(ResolvedAssembliesFixedUnix)" Condition="@(ResolvedAssembliesFixedUnix) != @(ResolvedAssemblies)" />
      <ResolvedAssemblies Condition="'@(ResolvedAssembliesFixed->Count())' &gt; 0" Remove="@(ResolvedAssemblies)" />
      <ResolvedAssemblies Include="@(ResolvedAssembliesFixed)" />
    </ItemGroup>
  </Target>
</Project>

Update: Fixed an issue where if there were no ref assemblies in the list, the ResolvedAssemblies would be emptied. Symptoms of that issue: Build failure with cannot find obj\linksrc\SomeAssembly.dll or an assembly not found error. The bug fix was adding a condition to only empty ResolvedAssemblies if ResolvedAssembliesFixed was not empty.

Any ETA for a fixed version of Xamarin.Android with these ?

I found another workaround: In my case, the NuGet package “System.Runtime.CompilerServices.Unsafe” caused the issue. So I made a copy of the package (*.nupkg file), removed the “ref”-folder from it (which contains the reference assemblies), and installed that modified package into my project.

Now that the package only contains the “real” assembly, there’s no way for Mono to accidentally pick the wrong assembly.