3
votes

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.

1
32bit or 64bit FSI ? - Functional_S
Don't know if you tried this or if it will help but can't hurt to mention it. See: Loading Native DLLs in F# Interactive - Guy Coder
@GuyCoder That's exactly what helped me get it working a few weeks back. - TeaDrivenDev
@Functional_S I tried both 32 & 64 bit FSI. Looks like the article Guy Coder posted has potential, trying that soon and will report back. - Jack Fox

1 Answers

3
votes

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"