Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite cannot execute from F# FSI

None of the SQLite .NET packages work in FSI, even when referencing a module in a fs project. I've tried System.Data.SQLite, SQLitePCL.raw, and Microsoft.Data.Sqlite.

From System.Data.SQLite docs:

If the executable that starts the process consists entirely of managed code, it will run with the native processor architecture of the machine, which will be x64 on an x64 machine. Later on, this will cause assemblies containing any native code compiled for x86 (e.g. the "System.Data.SQLite.dll" mixed-mode assembly, the "SQLite.Interop.dll" native interop assembly, or the "sqlite3.dll" native library) to fail to load, typically resulting in a BadImageFormatException being thrown.

The error thrown typically looks like

System.DllNotFoundException: Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(String filename, Sqlite3Handle& ppDb, Int32 flags, String vfs)
   at Microsoft.Data.Sqlite.SqliteConnection.Open()
   at <StartupCode$FSI_0009>.$FSI_0009.main@() in E:\BitSync\NonGitProjects\SQLiteSandbox\Microsoft.DataSandbox\Scripts\Script1.fsx:line 7

Demo gist

Has anyone found a solution to this? SQLite works just fine in compiled F# programs and in debug mode.

like image 902
Jack Fox Avatar asked Mar 23 '26 04:03

Jack Fox


1 Answers

The artice Loading Native DLLs in F# Interactive has correct techniques for solving the problem of loading native DLLS.

In my case in my case I successfully tried

System.Environment.CurrentDirectory <- @"D:\Projects\SQLiteSandbox\SQLiteSandbox\bin\Debug\x86"
like image 53
Jack Fox Avatar answered Mar 25 '26 01:03

Jack Fox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!