0

I'm having some troubles with loading the mod_spatialite extension in sqlite in an ASP.NET Core 3.1 application. When I run the code below I get the following error: "SQL logic error The specified module could not be found."

string dbFile = "D:\\Temp\\spatialtest.db";
string connectString = $"Data Source={dbFile};Version=3;";

SQLiteConnection connection = new SQLiteConnection(connectString);
connection.Open();
connection.EnableExtensions(true);
connection.LoadExtension("mod_spatialite");

I reference the System.Data.Sqlite(https://www.nuget.org/packages/System.Data.SQLite/1.0.113.1) package from NuGet. The packages I use for loading in spatialite are found here http://www.gaia-gis.it/gaia-sins/. I tried the packages from the current stable 4.3.0a and the new 5.0.0-RC1, both the amd64 and x86 binaries.

The weird thing is that when I copy the code to an .NET Core Console application or to an .NET Core Class Library(CL) and then reference the CL from the console application it does work.

I don't get why it does work in an Console application and not in an ASP.NET application. Am I missing something? Any help is greatly appreciated!

EDIT: Added test project to Github: https://github.com/RogierB/SQLiteSpatialiteTest

RogierBa
  • 45
  • 2
  • 7

2 Answers2

0

Probably in console application you are using EF? With EF installation for SQLite will be installed all necessary libraries.

Try to add this library

Install-Package SQLitePCLRaw.bundle_e_sqlite3 -Version 2.0.3
  • I'm not using EF within any of the projects(ASP.NET, Console, Library). Did add both packages (EF and SQLitePCLRaw.bundle_e_sqlite3) now to the ASP.NET project but I still get the same error. – RogierBa Aug 12 '20 at 14:13
  • I added a test project to Github: https://github.com/RogierB/SQLiteSpatialiteTest – RogierBa Aug 12 '20 at 14:43
0

I have found a working solution for my problem. I created a new folder and added all the files from the gaia download (http://www.gaia-gis.it/gaia-sins/) to that folder. The next thing I did was adding the newly created folder to the PATH environment variable for my system (Win 10). Restarted Visual Studio and now it does start and I don't even need to have the DLL's in the project/solution anymore because it will take the DLL's from the PATH

RogierBa
  • 45
  • 2
  • 7