Skip to content
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

Sqlite Spatial: dotnet 5.0.11 crashes when loading Spatial Extension #3534

Open
andrejohansson opened this issue Nov 2, 2021 · 4 comments
Open

Comments

@andrejohansson
Copy link

File a bug

I think I've ran in to something similar as dotnet/efcore#16667 but for version 5.0.11 instead.

According to the instructions on the sqlite spatial package I should be using the following imports

<ItemGroup>
  <!-- Use bundle_sqlite3 instead with SpatiaLite on macOS and Linux -->
  <!--<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />-->
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.1.0" />
  <PackageReference Include="SQLitePCLRaw.bundle_sqlite3" Version="2.0.4" />

  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="3.1.0" />
</ItemGroup>

I have replaced these with the current versions of the packages

    <!-- Use bundle_sqlite3 instead with SpatiaLite on macOS and Linux -->
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="5.0.11" />
    <PackageReference Include="SQLitePCLRaw.bundle_sqlite3" Version="2.0.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="5.0.11"/>

And added the following line to my docker file:

RUN apt-get install -y sqlite3 libsqlite3-mod-spatialite

I get the following error

dotnet/efcore#28 93.52   Error Message:
dotnet/efcore#28 93.52    System.TypeInitializationException : The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
dotnet/efcore#28 93.52 ---- System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
dotnet/efcore#28 93.52 -------- System.DllNotFoundException : Unable to load shared library 'sqlite3' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libsqlite3: cannot open shared object file: No such file or directory
dotnet/efcore#28 93.52   Stack Trace:
dotnet/efcore#28 93.52      at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
dotnet/efcore#28 93.52    at BokaMera.Api.IntegrationTest.Tests.BokaMeraContext.SeedTests.CanSeedContextAsync() in /app/Tests/BokaMera.Api.IntegrationTest/Tests/BokaMeraContext/SeedTests.cs:line 29
dotnet/efcore#28 93.52 --- End of stack trace from previous location ---
dotnet/efcore#28 93.52 ----- Inner Stack Trace -----
dotnet/efcore#28 93.52    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
dotnet/efcore#28 93.52    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
dotnet/efcore#28 93.52    at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
dotnet/efcore#28 93.52    at Microsoft.Data.Sqlite.SqliteConnection..cctor()
dotnet/efcore#28 93.52 ----- Inner Stack Trace -----
dotnet/efcore#28 93.52    at SQLitePCL.SQLite3Provider_sqlite3.NativeMethods.sqlite3_libversion_number()
dotnet/efcore#28 93.52    at SQLitePCL.SQLite3Provider_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()
dotnet/efcore#28 93.52    at SQLitePCL.raw.SetProvider(ISQLite3Provider imp)
dotnet/efcore#28 93.52    at SQLitePCL.Batteries_V2.Init()

Things work fine when running on Windows. Is there anything I'm missing with the instructions, or any workaround I can do to get up and running?

I tried setting LD_DEBUG=all when building the docker but it just truncates the output since there is way to much.

Include provider and version information

EF Core version: 5.0.11
Database provider: Microsoft.EntityFrameworkCore.Sqlite.Core
Target framework: .NET 5.0
Operating system: Ubuntu docker image: mcr.microsoft.com/dotnet/sdk:5.0-buster-slim

I understand from reading around that @bricelam have a lot of insight in the matter, is there anything obvious you see? Or anything I can do to provide more information?

@ajcvickers
Copy link
Member

/cc @bricelam

@bricelam
Copy link
Contributor

bricelam commented Nov 2, 2021

Have you installed the libsqlite3-dev package?

sudo apt install libsqlite3-dev

@andrejohansson
Copy link
Author

andrejohansson commented Nov 3, 2021

@bricelam that seems to have done the trick, thank you!

Perhaps this should be included in the instructions in the documentation page with an example of how to include in your csproj?

I did it the following way and it seems to be working for me:

# Install spatiallite in order to use nettopologysuite in integrationtests
RUN apt-get install -y sqlite3 libsqlite3-dev libsqlite3-mod-spatialite
  <ItemGroup Label="Windows only includes" Condition=" '$(OS)' == 'Windows_NT' ">
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.11" />
  </ItemGroup>

  <ItemGroup Label="Linux only includes" Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' ">
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="5.0.11"  />
    <PackageReference Include="SQLitePCLRaw.bundle_sqlite3" Version="2.0.7" />
  </ItemGroup>

@ajcvickers ajcvickers reopened this Nov 3, 2021
@ajcvickers ajcvickers transferred this issue from dotnet/efcore Nov 5, 2021
@ajcvickers ajcvickers added this to the Backlog milestone Nov 5, 2021
@ajcvickers
Copy link
Member

Consider including in docs.

@bricelam bricelam removed their assignment Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants