EntityFramework.Docs
EntityFramework.Docs copied to clipboard
Sqlite Spatial: dotnet 5.0.11 crashes when loading Spatial Extension
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?
/cc @bricelam
Have you installed the libsqlite3-dev
package?
sudo apt install libsqlite3-dev
@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>
Consider including in docs.