New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.EntityFrameworkCore.SQLite on Android 7+ not working #8922

Closed
tipa opened this Issue Jun 21, 2017 · 41 comments

Comments

Projects
None yet
@tipa
Copy link

tipa commented Jun 21, 2017

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

@tipa

This comment has been minimized.

Copy link

tipa commented Aug 18, 2017

Any comments/updates on this?

@bricelam

This comment has been minimized.

Copy link
Member

bricelam commented Aug 18, 2017

Have you tried again with EF Core version 2.0.0 and Xamarin.Android 7.5?

@tipa

This comment has been minimized.

Copy link

tipa commented Aug 18, 2017

How can I test it with Xamarin.Android 7.5? Version 7.4 was just released a few days ago

@erikpowa

This comment has been minimized.

Copy link

erikpowa commented Aug 19, 2017

@tipa Xamarin Updater Extension for VS 2017 (market). For older version of VS you can switch channels in vs->options->xamarin (not sure if alpha or beta).
I had the same error so I updated everything to the latest version, VS + NET Core (2.0+) + Xamarin Preview (I'm using Xamarin.Android 7.5.0.3 ), and everything is fine since then.

@tipa

This comment has been minimized.

Copy link

tipa commented Aug 19, 2017

@erikpowa that means I am forced to use VS17 Preview in order to use Xamarin.Android 7.5, is that correct? I would probably even do that if that finally resolves that issue.

Edit: well, downloaded VS17 preview + Xamarin.Android 7.5, however they still seem to be very beta, I encounter several issues which make it impossible for me to even compile the app.

@NPadrutt

This comment has been minimized.

Copy link

NPadrutt commented Aug 22, 2017

I have the same issue on the current stable and on the preview of Xamarin. But I still have the same issue..

@bricelam

This comment has been minimized.

Copy link
Member

bricelam commented Aug 22, 2017

(Marking for re-triage. Xamarin supports .NET Standard 2.0 now, but this still seems to be blocked.)

@bricelam bricelam removed this from the Backlog milestone Aug 22, 2017

@ajcvickers ajcvickers added this to the 2.1.0 milestone Aug 23, 2017

@groege

This comment has been minimized.

Copy link

groege commented Sep 4, 2017

Hi, this is very serious for us, since we are already shipping the Android app with netstandard1.4.
For now just no one use a Android 7+ phone, but now we might loose many important customers if we can't get it working very soon.
Can you give me any advice on how to handle this? Is there any workaround to make it work on Android 7+?
I'd be grateful for any help. Thanks.

@NPadrutt

This comment has been minimized.

Copy link

NPadrutt commented Sep 4, 2017

If you target 6.0 with your app and use EF 1.x it should work on Android 7+ as well. There is a message shown sometimes when you start, but you can just hit ok and it should be functional.

@groege

This comment has been minimized.

Copy link

groege commented Sep 4, 2017

Thank you! Didn't think there was an easy solution like this (though i also added this: #7870).
For now this is the better solution anyway until we can upload UWP projects to the app store with netcore2.0 ;)

@NPadrutt

This comment has been minimized.

Copy link

NPadrutt commented Sep 4, 2017

ah right. that one is also an important one :) Glad it worked :)

@tipa

This comment has been minimized.

Copy link

tipa commented Oct 10, 2017

Any updates on this? Same problem exists with Xamarin.Android 8.0 and VS17 Update 4.

@NPadrutt

This comment has been minimized.

Copy link

NPadrutt commented Oct 10, 2017

It seems the issue only appears with either project.json or package ref. With the old packages.config it seems to work so far.
I have two projects attached, one with packages.config (App1) und eines mit packagesRef (App2).

Desktop.zip

@mkuennek

This comment has been minimized.

Copy link

mkuennek commented Nov 8, 2017

I have the same problem, an update would be much appreciated

@alexdrl

This comment has been minimized.

Copy link

alexdrl commented Nov 17, 2017

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.

@erikpowa

This comment has been minimized.

Copy link

erikpowa commented Nov 17, 2017

@alexdrl

  1. use package.config and do a Clean Build
    or
  2. if you're using PackageReference, make sure you've manually added System.Runtime.CompilerServices.Unsafe 4.3.0 nuget package and do a Clean Build (delete obj/bin folders, restore nuget packages etc)
@tipa

This comment has been minimized.

Copy link

tipa commented Nov 19, 2017

Thanks - while both of your suggestions work, they feel like a workaround. Would be awesome if we wouldnt have to use them in the future

@alexdrl

This comment has been minimized.

Copy link

alexdrl commented Nov 20, 2017

@erikpowa We are in the point 2, using PackageReference. I cannot install System.Runtime.CompilerServices.Unsafe 4.3.0 because EF Core 2.0.0 uses the 4.4.0 version, so NuGet detects a package downgrade, and does not let me install 4.3.0.

@bytefish

This comment has been minimized.

Copy link

bytefish commented Nov 20, 2017

I investigated this a little. It seems like Microsoft.Extensions.Primitives has a dependency on System.Runtime.CompilerServices.Unsafe. When the Linker runs, it looks for the DLL in the directory of Microsoft.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 the NU1605 warning shouldn't be treated as an error:

<PropertyGroup>
  <NoWarn>$(NoWarn);NU1605</NoWarn>
</PropertyGroup>

Then in your Project File add the System.Runtime.CompilerServices.Unsafe Package in Version 4.3.0 as mentioned by @erikpowa:

<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.3.0" />

Then I would:

  1. Remove the App from the Device / Simulator
  2. Clean the NuGet Caches
  3. Clean all bin and obj folders
  4. Restore the Packages
  5. Build

After a successful build your Xamarin App should start with Entity Framework 2.0. 👍

@alexdrl

This comment has been minimized.

Copy link

alexdrl commented Nov 20, 2017

@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.

@NPadrutt

This comment has been minimized.

Copy link

NPadrutt commented Dec 5, 2017

When I add the System.Runtime.CompilerServices.Unsafe package I get an Exception during linking:

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2153,3): warning MSB3277: Found conflicts between different versions of "System.Runtime.CompilerServices.Unsafe" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.Void Microsoft.Extensions.Primitives.InplaceStringBuilder::Append(System.String,System.Int32,System.Int32)' in assembly: 'Microsoft.Extensions.Primitives.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void System.Runtime.CompilerServices.Unsafe::CopyBlockUnaligned(System.Void*,System.Void*,System.UInt32)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    --- End of inner exception stack trace ---
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessEntireQueue()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.Process()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Mono.Linker.Pipeline.Process(LinkContext context)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

So I have to set the linker to "None" instead of "SDK Assemblies only". Is there a work around for that? I already set the entry mentioned by @bytefish .

This happens on VS15.5.

@divega

This comment has been minimized.

Copy link
Member

divega commented Dec 12, 2017

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 area-external to distinguish them from any Xamarin-related issues we need to address on our side. Can you please help me make sure they are?

@softlion

This comment has been minimized.

Copy link

softlion commented Dec 14, 2017

@bytefish fix works but requires the linker set to "Don't link". This is not good.

@ConX-Ryan

This comment has been minimized.

Copy link

ConX-Ryan commented Jan 15, 2018

This is still an issue? is this being worked on or should i move to a more stable library for a new project?

@TheConservativeCoder

This comment has been minimized.

Copy link

TheConservativeCoder commented Jan 16, 2018

I had to move to Dapper because of this problem which works great on mobile but doesn't do migrations.

@dazinator

This comment has been minimized.

Copy link

dazinator commented Jan 16, 2018

I was using EF Core 2.0 just fine, and then issue only started occuring for me after I moved from packages.config to packagereference.
@bytefish
Adding a package reference to System.Runtime.CompilerServices.Unsafe 4.3.0 resulted in a package downgrade build error. I added the NoWarn for that error which allowed the build to proceed - which now gets as far as this linker error:

2>  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1696,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.Void Microsoft.Extensions.Primitives.InplaceStringBuilder::Append(System.String,System.Int32,System.Int32)' in assembly: 'Microsoft.Extensions.Primitives.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void System.Runtime.CompilerServices.Unsafe::CopyBlockUnaligned(System.Void*,System.Void*,System.UInt32)

Linker set to SdkOnly

Any ideas?

@JonDouglas

This comment has been minimized.

Copy link

JonDouglas commented Jan 16, 2018

We are tracking this issue in the following github issues:

xamarin/xamarin-android#1154
xamarin/xamarin-android#1196

@ajcvickers ajcvickers modified the milestones: 2.1.0-preview1, 2.1.0 Jan 17, 2018

@ddobrev

This comment has been minimized.

Copy link

ddobrev commented Jan 18, 2018

Using packages.config instead of package references works around the problem.

@dfoulk

This comment has been minimized.

Copy link

dfoulk commented Jan 19, 2018

Hey guys, not that it helps- but we had 3+ devs in our company alone run into this issue. So, for what it's worth, I don't think this is an isolated problem.

Latest Xamarin.Forms (.NET Standard) project + EntityFrameworkCore == runtime exception that only shows when deploying to an emulator.

Thanks,
-Derek

@ddobrev

This comment has been minimized.

Copy link

ddobrev commented Jan 19, 2018

@dfoulk it's even wider since it affects far more than EntityFrameworkCore. However, the workaround I've described does the job. For more details see xamarin/xamarin-android#1196 (comment) and below.

@dfoulk

This comment has been minimized.

Copy link

dfoulk commented Jan 19, 2018

@ddobrev - Yes, thank you for that. We're converting these projects to package.config- but a few errors seem to be preventing us from deploying still...

After following the instructions you provided in another thread:

Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.Dialog'.

No resource found that matches the given name: attr 'windowActionModeOverlay'.

styles.xml has apparently ran into some issues as a result :(

Update:

Something was wrong with our initial conversion. We reverted and tried again and all ended up okay... Thanks again!

@ddobrev

This comment has been minimized.

Copy link

ddobrev commented Jan 20, 2018

@dfoulk you're welcome. About that error, your conversion was just fine - it's just that Xamarin.Android is notoriously poor at rebuilding. Every time a major restructuring, such as yours, takes place, the only way to properly rebuild everything is after deleting your bin/ and obj/ - that is, neither rebuild nor clean + build work in such cases.

@jnormen

This comment has been minimized.

Copy link

jnormen commented Feb 2, 2018

Any news here? I cannot go back to 1.3 :( And really need EF with SQLite to work on our app in Android. How is this long delay of a fix even possible? :(

@dazinator

This comment has been minimized.

Copy link

dazinator commented Feb 2, 2018

I am using it in our monodroid 8 app - it is working.. I had to convert the project to using packages.xml instead of packagereference though.. I'm waiting for this issue to be fixes so that I can convert back to packagereference and drop packages.xml again..

@jnormen

This comment has been minimized.

Copy link

jnormen commented Feb 2, 2018

yes, it's the package reference scenario I want them to fix. It has been many converts back and forth already, because of other libs and I'm done spending time converting, my clients do not pay for that job :(

@divega divega removed their assignment Feb 5, 2018

@divega divega removed this from the 2.1.0 milestone Feb 5, 2018

@divega

This comment has been minimized.

Copy link
Member

divega commented Feb 5, 2018

Clearing milestone to decide in triage whether we want to keep this for tracking purposes or whether we should close.

The underlying issues in Xamarin Android are now tracked in xamarin/xamarin-android#1154 and xamarin/xamarin-android#1196.

@dfoulk

This comment has been minimized.

Copy link

dfoulk commented Feb 5, 2018

Thanks for the update @divega

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment