Skip to content

ResolveAssemblies task wrongly uses reference assemblies #1162

Closed

Description

@marek-safar

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

Activity

  1. changed the title [-]ResolveAssemblies tasks uses reference assemblies[/-] [+]ResolveAssemblies task wrongly uses reference assemblies[/+] on Jan 5, 2018
  2. self-assigned this
    on Jan 5, 2018
  3. added
    Area: dotnet/android Build
    on Jan 5, 2018
  4. added
    Area: App+Library Build
    and removed
    Area: dotnet/android Build
    on Jan 5, 2018
  5. GMariakis commented on Jan 11, 2018

    @GMariakis

    Until this is resolved, has a workaround been identified? Having this issue with System.Memory and System.Runtime.CompilerServices.Unsafe

  6. dellis1972 commented on Jan 11, 2018

    @dellis1972
    Contributor

    The only thing I can think of is to add a reference to the missing assemblies to the main app. And make sure you reference the lib versions.

  7. GMariakis commented on Jan 11, 2018

    @GMariakis

    That does not work. I have tried all the workarounds, such as changing the linker, adding the packages.config, etc. URLs below.

    I am trying to use SignalR Core in a Cross Platform Xamarin / Xamarin Forms app using .NET Standard as the code sharing mechanism. Getting the same two skips with the reason that it is a reference Assembly.

    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1500,2): warning : Ignoring /Users/xxxxxx/.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/xxxxxx/.nuget/packages/system.runtime.compilerservices.unsafe/4.4.0/ref/netstandard2.0 as it is a Reference Assembly

    https://forums.xamarin.com/discussion/113718/android-error-with-signalr-core-could-not-load-assembly-system-memory-during-startup-registration

    https://forums.xamarin.com/discussion/100273/deploying-to-android-emulator-error-could-not-load-assembly-system-runtime-compilerservices-unsafe

    https://github.com/aspnet/EntityFrameworkCore/issues/8922

  8. rwasef1830 commented on Jan 22, 2018

    @rwasef1830

    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.

  9. SvenEV commented on Jan 22, 2018

    @SvenEV

    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.

  10. dellis1972 commented on Jan 22, 2018

    @dellis1972
    Contributor

    That is an interesting workaround :) it that might cause some issues though. We are still working through this issue here, hopefully we will find a good soluition.

  11. GMariakis commented on Jan 22, 2018

    @GMariakis

    The problem with any of these workarounds, once I get it to build and deploy, the Xamarin Forms won't find and attach property changed notify for any fields. I spent a week trying to figure out why. The only thing I can think of is that there's an internal problem with these pre-release libraries.

  12. danielmeza commented on Mar 6, 2018

    @danielmeza

    @SvenEV your soulution work perfectly, I just open the .nupkg with WinRar and remove the ref folder, also from the package folder and the the application work fine
    image

  13. 10 remaining items

  14. added this to the d15-7 milestone on Mar 19, 2018
  15. added a commit that references this issue on Apr 1, 2018
  16. maddentist commented on Apr 3, 2018

    @maddentist

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

  17. rwasef1830 commented on Apr 12, 2018

    @rwasef1830

    To whomever used my workaround, there's a bug in it that breaks your build if there are no referenced .net standard libraries that use ref assemblies. The code is fixed now so it works even on a fresh project. Updated the comment: #1162 (comment)

  18. added a commit that references this issue on Jun 12, 2018
  19. added a commit that references this issue on Jul 20, 2018
  20. MagicAndre1981 commented on Aug 24, 2018

    @MagicAndre1981

    @maddentist I had to switch to packages.config for the Android App and this fixed my issue

  21. jrgsc commented on Oct 19, 2018

    @jrgsc

    I had this fix on my project for awhile now and completely forgot about it since. I loaded up my project on an updated version of VS and it wouldn't build. Took me awhile and a lot of sniffing around to figure out that this fix was the cause of my build issues. After removing it, my app now builds again.

  22. ghost locked as resolved and limited conversation to collaborators on Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: App+Library Buildvs-sync

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions