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
No error during execution.
[Mono] Assembly Loader probing location: 'System.Memory'.
[monodroid-assembly] Could not load assembly 'System.Memory' during startup registration.
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
/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
Until this is resolved, has a workaround been identified? Having this issue with System.Memory and System.Runtime.CompilerServices.Unsafe
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.
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
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())' > 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.
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.
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.
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.
@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

@svenEV and @danielmeza this unfortunately did not work in my case. I removed the system.runtime.compilerservices.unsafe v.4.4.0 from the android (forms) project using the nuget manager. I then added via the PM command line the modified system.runtime.compilerservices.unsafe.4.4.0.nupkg without the ref folder.
I still get the 'Could not load assembly 'system.runtime.compilerservices.unsafe' during startup registration' error.
@danielmeza you mentioned removing something from the packages folder but I am not sure what to remove. The Packages folder has a few folders with one file and the structure looks like package>services>metadata>core-properties>e1a986c2358d484f8041396b6b6d35c7.psmdcp
Did you remove this as well? I tried removing the .psmdcp file and got the same results.
I also tried installing the system.runtime.compilerservices.unsafe 4.5.0-preview1-26216-02 from nuget and got the same results.
@brian8227 Are you 100% sure that your modified package got installed and not the original/official one from NuGet? In my case, the modified package was correctly installed on my machine, but on another machine VS somehow preferred the original package from NuGet and the error appeared again. Since I don't know about the precedence of NuGet package sources, I solved the issue by simply assigning a different version number to the modified package, e.g. "4.4.0-patched".
@SvenEV Thanks
I really thought that was the case once you mentioned it as well.
Originally I did a PM> install-package c:\users\brian\desktop\system.runtime.compilerservices.unsafe.4.4.0.nupkg
I am not saying VS2017 couldn't have done something else in the background but that was the command I used after uninstalling the original it is very likely it grabbed another package.
I just tried modifying the file as you suggested
PM> install-package c:\users\brian\desktop\System.Runtime.CompilerServices.Unsafe.4.4.0-patched.nupkg
Restoring packages for C:\Users\Brian\Documents\Visual Studio 2017\Projects\TMMobile2\TMMobile2\TMMobile2.Android\TMMobile2.Android.csproj...
Installing System.Runtime.CompilerServices.Unsafe 4.4.0-patched.
Committing restore...
Writing lock file to disk. Path: C:\Users\Brian\Documents\Visual Studio 2017\Projects\TMMobile2\TMMobile2\TMMobile2.Android\obj\project.assets.json
Restore completed in 184.56 ms for C:\Users\Brian\Documents\Visual Studio 2017\Projects\TMMobile2\TMMobile2\TMMobile2.Android\TMMobile2.Android.csproj.
Successfully uninstalled 'System.Runtime.CompilerServices.Unsafe 4.4.0' from TMMobile2.Android
Successfully installed 'System.Runtime.CompilerServices.Unsafe 4.4.0-patched' to TMMobile2.Android
Executing nuget actions took 2.27 sec
Time Elapsed: 00:00:02.4919885
PM>
I verified in the csproj file this:
I still get the error
03-14 16:17:54.996 D/Mono (26724): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
03-14 16:17:54.997 F/monodroid-assembly(26724): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
03-14 16:17:54.997 F/monodroid-assembly(26724): This might be due to an invalid debug installation.
03-14 16:17:54.997 F/monodroid-assembly(26724): A common cause is to 'adb install' the app directly instead of doing from the IDE.
Perhaps I didn't modify the file correctly? I just removed the Ref folder edited the metadata version number and then saved it with the matching version name. I used Nuget Package Explorer by Luan Nguyen which seems to do what I needed.
Any ETA for a fixed version of Xamarin.Android with these ?
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: https://github.com/xamarin/xamarin-android/issues/1162#issuecomment-359475008
@maddentist I had to switch to packages.config for the Android App and this fixed my issue
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.
Most helpful comment
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.BuffersUpdate: Fixed an issue where if there were no ref assemblies in the list, the
ResolvedAssemblieswould be emptied. Symptoms of that issue: Build failure with cannot findobj\linksrc\SomeAssembly.dllor an assembly not found error. The bug fix was adding a condition to only empty ResolvedAssemblies if ResolvedAssembliesFixed was not empty.