efcore: Microsoft.EntityFrameworkCore.SQLite on Android 7+ not working
I was successfully using Microsoft.EntityFrameworkCore.SQLite v.1.1.2
in a Xamarin.Android project. But for Android 7+, the app crashes with unauthorized access to "/system/lib64/libsqlite.so"
(as reported here).
So I updated to version v2.0.0-preview1-final
as this should fix the issue.
However, this results in other problems like the following where the app compiled, but crashed while deploying/starting on the emulator:
...
06-21 09:58:18.970 D/Mono ( 3632): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
06-21 09:58:18.970 F/monodroid-assembly( 3632): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
06-21 09:58:18.970 F/monodroid-assembly( 3632): This might be due to an invalid debug installation.
I then tried to add the ‘System.Runtime.CompilerServices.Unsafe’ NuGet package manually to my project, but it didnt fix the problem. I messed around a lot, trying different build parameters and such and actually got the app running on an Android 7 emulator. However, after a project clean and rebuild, the error showed up again.
Any help on how to get EFCore Sqlite to work on Android 7?
Steps to reproduce
Sample project: https://github.com/tipa/EFCoreSample (Basically just the basic Android template from VS + the Nuget preview package)
Further technical details
EF Core version: v2.0.0-preview1-final Database Provider: Microsoft.EntityFrameworkCore.Sqlite Xamarin: 4.5.0.486 Xamarin.Android: 7.3.1.2 Operating system: Windows 10 IDE: Visual Studio 2017 15.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 41 (5 by maintainers)
@alexdrl
Thanks @bricelam. I started an email thread with the Xamarin folks to figure out with them how to best manage this and other issues that were reported here but appear to be Xamarin issues.
At least for now, I would like to make sure such issues are also marked <kbd>area-external</kbd> to distinguish them from any Xamarin-related issues we need to address on our side. Can you please help me make sure they are?
I investigated this a little. It seems like
Microsoft.Extensions.Primitives
has a dependency onSystem.Runtime.CompilerServices.Unsafe
. When the Linker runs, it looks for the DLL in the directory ofMicrosoft.Extensions.Primitives
, which is not downloaded by NuGet.I have downloaded the NuGet Package
System.Runtime.CompilerServices.Unsafe
4.4.0, extracted the DLL and linked it with a normal Reference. This way it will be copied into the output directories and can be linked.This is my previous workaround:
@alexdrl I think the following trick is necessary to make it work.
Manually edit the
csproj
file of your project and define, that theNU1605
warning shouldn’t be treated as an error:Then in your Project File add the
System.Runtime.CompilerServices.Unsafe
Package in Version4.3.0
as mentioned by @erikpowa:Then I would:
bin
andobj
foldersAfter a successful build your Xamarin App should start with Entity Framework 2.0. 👍
@bytefish @erikpowa That workaround worked good… as we’re working closely to the latest version of .NET Core/Standard and Xamarin, could you give us some explanation of why is this happening?
Thank you for the workaround.
Also, as we have found with other package version mismatch, this package downgrade workaround breaks the assemblies linking.
@divega Can we follow up with the Xamarin Android team on this?
We’re having the same issue using EF Core 2.0.1 in VS 15.4.3 and VS 15.5 Preview 3 with no luck.
This is annoying because the Xamarin application is now blocked because of this.
ah right. that one is also an important one 😃 Glad it worked 😃