View Ticket
Not logged in
Ticket Hash: f2e586715f5cc53669171d8cc506f22841a71b7c
Title: Unable to enable extension loading in c#
Status: Closed Type: Question
Severity: Important Priority: Medium
Subsystem: Integration_Via_PInvoke Resolution: Unable_To_Reproduce
Last Modified: 2017-04-05 15:18:43
Version Found In:
User Comments:
anonymous added on 2017-04-04 12:43:29:
Dear developers,

as the titles spcifies I'm unable to load extensions (specifically mod_spatialite) in a C# project using I get an "not authorized" error from SQLite as soon as I try to load mod_spatialite.

My code is as follows

String inputFile = "SomeDatabase.db";
dbConnection = "Data Source=" + inputFile;
connection = new SQLiteConnection(dbConnection);
connection.SetConfigurationOption(SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, true);

SQLiteCommand version = new SQLiteCommand("SELECT sqlite_version();");  // this works fine
Console.WriteLine("SQLITE-Version: " + ExecuteScalar(version).ToString());  // returns "SQLITE-Version: 3.15.2"

SQLiteCommand loadSpatialite = new SQLiteCommand("SELECT load_extension('mod_spatialite');");
ExecuteNonQuery(loadSpatialite);  // crashes throwing a "not authorized"  message

ExecuteNonQuery() and ExecuteScalar() are consisting basically of the SQLiteCommand inside a try/catch block and setting the connection before executing)

Neither EnableExtensions(true) nor modifying the configuration options seems to show any effect.

At the same time, I can load mod_spatialite without any issues from the sqlite console. 

I of course tried with both, the pre-compiled binarys (VS2015, win64) and an own compile from the source.

(All compiles and dlls 64bit.)

connection.LoadExtension() does alwas return "specified module not found". This is does happen for Filename and absollute, as well as with relative Path, and with only the file name. 


mistachkin added on 2017-04-04 20:15:53:
This type of question is better handled on the mailing list:


That being said, I think the issue MAY be a 32-bit versus 64-bit native binary
issue -OR- that the necessary native runtime(s) are not installed.

anonymous added on 2017-04-05 15:18:43:
Hi there!

The module not found was due to an architecture mismatch within a dependency, as you suspected correctly. Thanks for making me check!

However, I can definitely confirm, that I can load mod_spatialite with


no matter if

MyConnection.SetConfigurationOption(SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, true);

are set to true or false.
At the same time,

SQLiteCommand loadSpatialite = new SQLiteCommand("SELECT load_extension('mod_spatialite');");

does never work (but used to do so in previous versions).