Deploying to android emulator error:Could not load assembly 'System.Runtime.CompilerServices.Unsafe'

abraabra ADMember ✭✭✭

When trying to deploy Xamarin.Forms to android emulator the following message is displayed in VS2017 output window.

07-27 10:31:25.512 D/Mono ( 3680): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
07-27 10:31:25.512 F/monodroid-assembly( 3680): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
07-27 10:31:25.512 F/monodroid-assembly( 3680): This might be due to an invalid debug installation.
07-27 10:31:25.512 F/monodroid-assembly( 3680): A common cause is to 'adb install' the app directly instead of doing from the IDE.

Initially the application could be deployed without any problems to the android emulator.
The last change that I did was adding a custom WebViewRender. Could the fail of the application deployment be related to that ?

Posts

  • awcullenawcullen USMember

    Hi Abra,
    I was able to get .NetStandard 2.0 library 'System.Runtime.CompilerServices.Unsafe' v4.4.0 to deploy to Android emulator by returning to the packages.config file.

    I have no idea why, there must be something wrong in the vs or nuget tooling.

    Here's the packages.config:

    <?xml version="1.0" encoding="utf-8"?>
    <packages>
      <package id="Microsoft.Extensions.Configuration" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.Configuration.Binder" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.Logging" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.Logging.Debug" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.Options" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Extensions.Primitives" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="monoandroid71" />
      <package id="NETStandard.Library" version="2.0.0" targetFramework="monoandroid71" />
      <package id="Portable.BouncyCastle" version="1.8.1.3" targetFramework="monoandroid71" />
      <package id="System.AppContext" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Collections" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.ComponentModel" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Console" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Diagnostics.Contracts" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Dynamic.Runtime" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Globalization" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Globalization.Calendars" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.IO" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.IO.Compression" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.IO.FileSystem" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Linq" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Linq.Expressions" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Net.Http" version="4.3.2" targetFramework="monoandroid71" />
      <package id="System.Net.Primitives" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Net.Sockets" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.ObjectModel" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Reactive" version="3.1.1" targetFramework="monoandroid71" />
      <package id="System.Reactive.Core" version="3.1.1" targetFramework="monoandroid71" />
      <package id="System.Reactive.Interfaces" version="3.1.1" targetFramework="monoandroid71" />
      <package id="System.Reactive.Linq" version="3.1.1" targetFramework="monoandroid71" />
      <package id="System.Reactive.PlatformServices" version="3.1.1" targetFramework="monoandroid71" />
      <package id="System.Reflection" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Reflection.Extensions" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Reflection.Primitives" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Runtime" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Runtime.CompilerServices.Unsafe" version="4.4.0" targetFramework="monoandroid71" />
      <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Runtime.Handles" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Runtime.InteropServices.WindowsRuntime" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Text.Encoding" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Threading" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Threading.Tasks" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Threading.Tasks.Dataflow" version="4.8.0" targetFramework="monoandroid71" />
      <package id="System.Threading.Timer" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="monoandroid71" />
      <package id="System.Xml.XDocument" version="4.3.0" targetFramework="monoandroid71" />
      <package id="UrhoSharp.Forms" version="1.5.20" targetFramework="monoandroid71" />
      <package id="Workstation.UaClient" version="2.1.0" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Annotations" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Compat" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Core.UI" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Core.Utils" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Design" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Fragment" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Media.Compat" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Transition" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.v4" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.v7.AppCompat" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.v7.CardView" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.v7.MediaRouter" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.v7.Palette" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.v7.RecyclerView" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Android.Support.Vector.Drawable" version="25.4.0.2" targetFramework="monoandroid71" />
      <package id="Xamarin.Forms" version="2.3.4.270" targetFramework="monoandroid71" />
    </packages>
    
    
  • abraabra ADMember ✭✭✭

    Thank you for your reply, the problem unfortunately persists also with newest Visual Studio 15.4.1.
    Did you used a shared project for the cross-platform code ?
    I do not used shared projects, but am referencing .Net standard libraries from the Android project. In my case it does not seem to help moving the Android project nuget packages into packages.config, still getting the above error message.

  • DanielMezaDanielMeza COMember ✭✭

    I have the same issue, when adding a IdentityModel.OidcClient

  • zahikramerzahikramer ILMember ✭✭✭

    Same issue for me.
    Is it related to build tools updated to 27.0 ???

  • MEJMEJ DEMember ✭✭

    Same problem here

  • DanielMezaDanielMeza COMember ✭✭
    edited December 2017

    Hi guys I have been tracking this issue a week ago and I finally temporarily solved it
    just change the Linker option in the android project from none to Sdk and User Assemblies and in iOS projecto fron none to Link Framework SDKs Only option

    You can track the issue on github here

  • DanielMezaDanielMeza COMember ✭✭

    ny notice about this issue? it is a major issue, many people are affected.

  • zahikramerzahikramer ILMember ✭✭✭

    @DanielMeza said:
    ny notice about this issue? it is a major issue, many people are affected.

    It is on investigation : https://github.com/xamarin/xamarin-android/issues/1196

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

    But, for me, adding the reference explicitly and working with preview 15.6(.2) worked.

Sign In or Register to comment.