Join GitHub today
System.Runtime.CompilerServices.Unsafe linked away in release leading to crashes #1196
This is most probably related to dotnet/efcore#8922 . None of the workarounds there help. The major problem is that it's simply impossible to force the linker to preserve an entire assembly.
Steps to Reproduce
The application runs.
The application does not load at all with:
Microsoft Visual Studio Community 2017
Installed Version: Community
Visual Basic 2017 00369-60000-00001-AA416
Visual C# 2017 00369-60000-00001-AA416
Visual C++ 2017 00369-60000-00001-AA416
Visual F# 4.1 00369-60000-00001-AA416
Application Insights Tools for Visual Studio Package 8.10.01106.1
ASP.NET and Web Tools 2017 15.0.31127.0
ASP.NET Core Razor Language Services 1.0
ASP.NET Web Frameworks and Tools 2017 5.2.51007.0
Azure App Service Tools v3.0.0 15.0.31106.0
Common Azure Tools 1.10
Merq 1.1.17-rc (cba4571)
Microsoft Azure Tools 2.9
Microsoft Continuous Delivery Tools for Visual Studio 0.3
Microsoft JVM Debugger 1.0
Microsoft MI-Based Debugger 1.0
Microsoft Visual C++ Wizards 1.0
Microsoft Visual Studio Tools for Containers 1.1
Microsoft Visual Studio VC Package 1.0
Mono Debugging for Visual Studio 4.8.4-pre (3fe64e3)
NpgsqlVSPackage Extension 1.0
NuGet Package Manager 4.5.0
Qt Visual Studio Tools 2.1.2
SQL Server Data Tools 15.1.61710.120
Visual Studio Code Debug Adapter Host Package 1.0
Visual Studio Tools for CMake 1.0
Xamarin 184.108.40.2067 (7f9ec2a)
Xamarin Designer 4.8.188 (c5813fa34)
Xamarin.Android SDK 220.127.116.11 (HEAD/ef47226b7)
Xamarin.iOS and Xamarin.Mac SDK 18.104.22.168 (6857dfc)
@radekdoulik: "Reference only assembly" means Issue #1154. It is an assembly with the
Mono will not load reference assemblies.
OK, I have got a link to a simple app from @JonDouglas which reproduces the issue - https://github.com/aspnet/EntityFrameworkCore/files/1372571/Desktop.zip (App2). Looks like it is indeed related to #1154
A simple reproduction is the following:
Here are some relevant logs similar to those in #1154
I have just hit this after converting my csproj from using packages.config to using packagereference. Prior to that my app was working but I had to use linker mode "SdkOnly". Now after converting to package reference, system.runtime.compilerservices.unsafe gets linked away.
@ddobrev I don't know about any workaround at this point. At least not from linker perspective as the assembly is not removed by the linker. It is present in the apk, but it is not loaded because it has
As can be seen from logcat output:
In case you are using
@JORGEGO 15.5.4 had no fixes for Xamarin.Android. We do not have a direct fix for this issue yet as the only known workaround is to use
I've resolved it by following:
This is a netstandard 2 project (xamarin.forms). I have tried a number of ways to get it to revert to packages.config approach. Including this approach as shown on SO https://stackoverflow.com/questions/45962998/switch-back-to-packages-config
So, at this moment wanting to use ef.core sqllite with xamarin forms .netstandard2 project and struggling to get it back to packages.config approach.
Gosh, I have tried a number of the variations above, modifying nupkg, removing lib's, refs, dlls, reinstalled etc. Still no solution to this error
04-07 15:46:50.825 D/Mono (29229): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
I follow these steps of hongliyu2002 https://forums.realm.io/t/could-not-load-assembly-system-runtime-compilerservices-unsafe-during-startup-registration/974/4
1. Go to C:\Users%user%.nuget\system.runtime.compilerservices.unsafe\4.4.0, and delete "ref" folder then make a copy of "lib" folder and rename the copy back to "ref".
This simple workaround , works for me :)
@alexdrl Odd -- I am not encountering the issue. I am able to compile and run the Android app in the latest version of the sample (https://github.com/cwrea/XamarinTodo/tree/NETStd20_EFCore203 and corresponding to
When I created that version, I did specifically remove the
Did you upgrade any packages or make any other changes, or ran the build from unmodified source?
@cwrea The only thing that I do is to extract the zip downloaded from GitHub, and build+run the Project in VS.
I confirm that the versions of VS and Xamarin.Android SDK are the same that you mention
Doing this solves the problem #1196 (comment)