Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Microsoft.EntityFrameworkCore.SQlite fails with Xamarin.Forms 4.1.x on IOS #7179

Closed
matt-goldman opened this issue Aug 16, 2019 · 15 comments
Labels
i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛

Comments

@matt-goldman
Copy link

matt-goldman commented Aug 16, 2019

Description

When the EnsureCreatedAsync() method is called, a System.ArgumentNullException is thrown with

Value cannot be null. Parameter name: key.

Steps to Reproduce

  1. Create a Xamarin.Forms 4.1+ project
  2. Add Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.sqlite packages (both on version 2.2.6).
  3. Add a context, and in the constructor (or elsewhere) call the EnsureCreatedAsync() method
  4. Run the project on a physical device (problem only intermittently occurs on simulators)

Expected Behaviour

Database should be created or verified. This behaviour occurs as expected when running Xamarin.Forms 3.6.x. Expected behaviour also occurs in Android simulator .

Actual Behaviour

System.ArgumentNullException is thrown

Basic Information

  • Version with issue: 4.1.x (all tested versions > 4.1)
  • Last known good version: 3.6.x

=== Visual Studio Community 2019 for Mac (Preview) ===

Version 8.3 Preview (8.3 build 867)
Installation UUID: 1e1fc119-c410-43fb-b3d5-b89f27185206
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.0.5 (d16-3 / 26f04c54)

Package version: 604000081

=== Mono Framework MDK ===

Runtime:
Mono 6.4.0.81 (2019-06/f55e0a671c0) (64-bit)
Package version: 604000081

=== NuGet ===

Version: 5.2.0.6067

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.2.4
2.2.1
2.1.9
2.1.2
2.0.5
SDK: /usr/local/share/dotnet/sdk/2.2.203/Sdks
SDK Versions:
2.2.203
2.2.102
2.1.505
2.1.302
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.10
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 10.2.1 (14490.122)
Build 10E1001

=== Xamarin.Mac ===

Version: 5.16.0.5 (Visual Studio Community)
Hash: 26f04c54
Branch: d16-3
Build date: 2019-06-28 01:31:14-0400

=== Xamarin.iOS ===

Version: 12.16.0.5 (Visual Studio Community)
Hash: 26f04c54
Branch: d16-3
Build date: 2019-06-28 01:31:14-0400

=== Xamarin Designer ===

Version: 16.3.0.17
Hash: 73f0a446c
Branch: remotes/origin/d16-3-release-8.3-p1
Build date: 2019-07-22 17:05:22 UTC

=== Xamarin.Android ===

Version: 9.5.0.27 (Visual Studio Community)
Commit: xamarin-android/d16-3/16c4494
Android SDK: /Users/xxx/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
6.0 (API level 23)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.2
SDK Build Tools Version: 27.0.3

Build Information:
Mono: mono/mono@e6f5369c2d2
Java.Interop: xamarin/java.interop/d16-3@5836f58
LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
LibZip: nih-at/libzip@b95cf3f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/xxx/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 1.4.0.8
Hash: 28342d0
Branch: remotes/origin/backport-pr-235-to-d16-3~2
Build date: 2019-07-18 16:54:46 UTC

=== Android Device Manager ===

Version: 1.2.0.75
Hash: bf6d603
Branch: remotes/origin/backport-pr-369-to-d16-3~1
Build date: 2019-07-18 16:55:08 UTC

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 803000867
Git revision: ab4af85ea561e474b545e0eada75c5bfe8a92297
Build date: 2019-07-24 14:13:44+00
Build branch: release-8.3-preview1
Xamarin extensions: 45290013e165bcd2db7acbb310e0c16bfe04f0c3

=== Operating System ===

Mac OS X 10.14.6
Darwin 18.7.0 Darwin Kernel Version 18.7.0
Thu Jun 20 18:42:21 PDT 2019
root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

XAML Styler 1.1.3
MFractor 3.8.16
Xamarin.HotReload 1.0.0.2910000

Reproduction Link

https://github.com/matt-goldman/SQLiteTest

@matt-goldman matt-goldman added s/unverified New report that has yet to be verified t/bug 🐛 labels Aug 16, 2019
@matt-goldman
Copy link
Author

Here is the stack trace from when this happens

2019-08-16 07:08:01.337 SQLiteTest.iOS[32921:2851415] error: Failed to load AOT module 'data-0x112ed8000.so' in aot-only mode.

=================================================================
    Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
    Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0x1941610cc):0x1941610bc  fd 7b c1 a8 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .{...._..)......
0x1941610cc  c3 00 00 54 fd 7b bf a9 fd 03 00 91 3f d5 ff 97  ...T.{......?...
0x1941610dc  bf 03 00 91 fd 7b c1 a8 c0 03 5f d6 90 29 80 d2  .....{...._..)..
0x1941610ec  01 10 00 d4 c3 00 00 54 fd 7b bf a9 fd 03 00 91  .......T.{......

=================================================================
    Native stacktrace:
=================================================================
    0x105f84d18 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x105f7b1d8 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x1941d44f0 - /usr/lib/system/libsystem_platform.dylib : <redacted>
    0x1941d8a88 - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
    0x1940ba14c - /usr/lib/system/libsystem_c.dylib : abort
    0x1060f3e0c - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : xamarin_find_protocol_wrapper_type
    0x1060d3f34 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x1060d3f84 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f61a90 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x105fb72b8 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105fb3104 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105fee7b0 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x100b1b094 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x100b1b1c4 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x100b1b158 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x100b1af7c - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x100ca988c - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x10129d2bc - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x105f8bc84 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x10602e450 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f9767c - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f96b44 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f96c84 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f96c84 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f9c600 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f95610 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105fadd70 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f941f8 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x1013102b4 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x1009ccabc - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x10129d2bc - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x105f8bc84 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x10602ca98 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x1060320e4 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : mono_pmip
    0x105f701a0 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x106103628 - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : xamarin_localized_string_format_9
    0x1009cc9cc - /var/containers/Bundle/Application/06702566-C641-4954-A671-29967CE5DF53/SQLiteTest.iOS.app/SQLiteTest.iOS : (null)
    0x194014fd8 - /usr/lib/system/libdyld.dylib : <redacted>

=================================================================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at System.AppDomain:LoadAssemblyRaw <0x00007>
      at System.AppDomain:Load <0x00053>
      at System.AppDomain:Load <0x00047>
      at System.AppDomain:Load <0x0003b>
      at System.Reflection.Assembly:Load <0x0003b>
      at System.Object:runtime_invoke_dynamic <0x0011b>
      at <unknown> <0xffffffff>
      at SQLiteTest.iOS.Application:Main <0x0006b>
      at System.Object:runtime_invoke_dynamic <0x0011b>
=================================================================

@PureWeen
Copy link
Contributor

@matt-goldman is this by chance something that happened when you updated to 8.3 preview?

I'm testing locally and I get this same exception even when running XF 3.5
Have you asked over at * Microsoft.EntityFrameworkCore.SQlite* to see if it looks familiar to thm?

pinging @spouliot on this one in case the exception looks familiar to him

@matt-goldman
Copy link
Author

@PureWeen that's possible - I'm finding this issue now to be intermittent (currently getting this on XF3.6 running on the simulator but not on physical device). I can no longer reliably create a scenario that either does or doesn't cause this issue, so at this point I'm a little lost.

I haven't logged this with Microsoft.EntityFrameworkCore.SQLite, thanks for pinging.

@matt-goldman
Copy link
Author

matt-goldman commented Aug 17, 2019

Sorry, spoke too soon. By disabling linking it works fine in 3.6 on both physical device and simulator, but this has no impact when using XF4.1.

@PureWeen
Copy link
Contributor

Is it the same exception on 3.6 and XF 4.1?

What you might try is to figure out the linker settings required to make it work on 3.6
https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=windows
https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker

once you've done that I would be curious if it then starts working for you on 4.1

@matt-goldman
Copy link
Author

I set the linker to 'don't link', I could try a more precise configuration but I would have thought that without linking altogether it's not likely that there'd be another setup that would work. I haven't tried specifically preserving parts of the XF or SQLite assembly, do you think this would be worthwhile? As I said setting the linker to Don't Link should just preserve everything.

@PureWeen
Copy link
Contributor

do you think this would be worthwhile?

You won't really want to release the app with the linker totally off so it's something that I think would need to eventually be figured out

As I said setting the linker to Don't Link should just preserve everything.

It should but I was just curious if you figured out the linker settings that made it work with 3.6 if a similar setup would make it work for 4.1. If it did then that might help figure out why it's being finicky on 4.1

@StevenGranados
Copy link
Contributor

What I did was downgrade to 2.1 and add
[assembly: Preserve (typeof (System.Linq.Queryable), AllMembers = true)]
to the iOS Main.cs as a workaround.
https://stackoverflow.com/questions/53521581/xamarin-ios-linker-issue

@matt-goldman
Copy link
Author

@PureWeen understood, apologies I'm a little out of my depth here.
@StevenGranados I tried this with 4.1/2.2.6 to no avail, will experiment with with 4.1/2.1 and 3.6/2.1 and feedback results.

@PureWeen
Copy link
Contributor

pinging @jgold6 as it looks like he's familiar with this issue :-)

@matt-goldman
Copy link
Author

Confirming that using Xamarin.Forms 4.1.0.673156 and Microsoft.EntityFrameworkCore.SQLite 2.1.0 works with the added preserve directive. Linker behvaiour set to Link Platform SDKs Only, tested on iPhone XS Max (physical) and iPhone Xr (simulator), debug and release mode on both, iPhone 6 and 6s (simulators) in debug mode, worked in all scenarios.

@samhouts samhouts added i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 labels Aug 20, 2019
@samhouts
Copy link
Member

@matt-goldman Does that mean that this issue is resolved and good to close? Thanks!

@matt-goldman
Copy link
Author

@samhouts We've identified a workaround but it looks like XF 4.1 and EFCore SQLite 2.2.6 are incompatible. I don't know which side the problem is on, but if the team are happy for this to be closed with the appropriate workaround in place than I guess that's ok. Otherwise not sure if this needs to be kept open until the root cause is found and fixed.

@samhouts
Copy link
Member

@matt-goldman This is not unique to Xamarin.Forms. I'm unclear why you're seeing different behavior with 3.6, but the root cause is dotnet/efcore#10963. I will go ahead and close this report in favor of that one. Thank you!!

@PureWeen
Copy link
Contributor

@matt-goldman here's a linker setup that might work for you

xamarin/xamarin-macios#3394 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests

4 participants