efcore: Sqlite Spatial: dotnet crashes when loading Spatial Extension (segmentation fault)
I’m trying to test out the Spatial Types functionality in EF Core for SQLite In Memory provider.
Now when I run an Xunit test the dotnet executable crashes and I will receive a crash dump report (No application exceptions are thrown).
It seems to crash when trying to access the mod_spatialite extension. I followed the following advice from this issue https://github.com/aspnet/EntityFrameworkCore/issues/14402, as my original problem was with receiving a SQLite Exception with a no such function: InitSpatialMetaData error to begin with.
Steps to reproduce for Mac
git clonehttps://github.com/StratumFive/EFCore.SQLite.SpatialCrash.brew install libspatialit- Change directory to the root solution.
dotnet test xunit- Receive error message:
The active test run was aborted. Reason: Test host process crashed
There is even a console application there to prove it isn’t just a Xunit issue.
Further technical details
EF Core version: 2.2.6 Database Provider: Microsoft.EntityFrameworkCore.Sqlite / Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite Operating system: Mac Mojave 10.14.5 IDE: Visual Studio Code SQLite version: 3.24.0 2018-06-04 14:10:15 dotnet info:
.NET Core SDK (reflecting any global.json): Version: 2.2.300 Commit: 73efd5bd87
Runtime Environment: OS Name: Mac OS X OS Version: 10.14 OS Platform: Darwin RID: osx.10.14-x64 Base Path: /usr/local/share/dotnet/sdk/2.2.300/
Host (useful for support): Version: 2.2.5 Commit: 0a3c9209c0
.NET Core SDKs installed: 2.2.105 [/usr/local/share/dotnet/sdk] 2.2.106 [/usr/local/share/dotnet/sdk] 2.2.107 [/usr/local/share/dotnet/sdk] 2.2.300 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 33 (19 by maintainers)
Commits related to this issue
- Document PROJ workarounds Mitigates dotnet/efcore#16667 — committed to bricelam/EntityFramework.Docs by bricelam 4 years ago
- Document PROJ workarounds Mitigates dotnet/efcore#16667 — committed to bricelam/EntityFramework.Docs by bricelam 4 years ago
Just make sure not to file issues with homebrew if you install old versions this way since it isn’t supported.
Oh wait, if you’re using 2.2, you can just do this:
Take heart and have a look at https://github.com/ericsink/SQLitePCL.raw/blob/master/src/SQLitePCLRaw.nativelibrary/for_netstandard2.cs
Another workaround is to manually build and install SpatiaLite without PROJ support:
I was able to confirm my suspicions. This issue stems from PROJ using its own version of SQLite. Here are the relevant parts of the LD_DEBUG log:
Calling load_extension(‘mod_spatialite’) from e_sqlite3 causes the system sqlite3 library to be loaded as a dependency. Then it tries to call sqlite3_extension_init() in mod_spatialite, but it can’t reconcile the two versions of SQLite and crashes.
If I take e_sqlite3 out of the picture and only use the system sqlite3 version, everything works as expected. (https://github.com/ericsink/SQLitePCL.raw/issues/325 would make this easier)
I didn’t get a response from SpatiaLite. I’m working on just building it myself without PROJ over in bricelam/mod_spatialite-NuGet
@bricelam Should be able to go to 5.2.0 via
I tried this and while my own test suite continued to build, I didn’t have much luck with the one in the https://github.com/Homebrew/homebrew-core/issues/43203 example repository. Worth a try on your local machine though as there are many other things that might have caused problems on my old laptop.
Unfortunately, we are out of ideas here. We are going to put this on the backlog, but we are likely to need expert help to make real progress here.
It may (or may not) be related to the fact that our native SQLite library is named libe_sqlite3.dylib not libsqlite3.dylib
I don’t think so. I just need to repro it locally and dig into the failure.