Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting DllNotFoundException when adding SQLite Nuget Package to LINQPad?

I have added the System.Data.SQLite.Core NuGet package to my LINQPad 5 Query (Premium) and then try to execute the following:

new SQLiteConnection(":memory:").Dump();

But I get:

DllNotFoundException: Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

How can I tell LINQPad where to find the SQLite Native DLLs?

Please note I do not want to use the IQ Driver.

like image 583
MaYaN Avatar asked Jan 15 '16 17:01

MaYaN


2 Answers

This library is not referenced in the standard way, because it's native and requires different images for X86 and X64.

A workaround in LINQPad is to locate the following folder:

%localappdata%\LINQPad\NuGet.FW46\System.Data.SQLite.Core\System.Data.SQLite.Core.1.0.99.0\build\net46

and copy the X86 and X64 subfolders into the folder where LINQPad.exe is located.

like image 142
Joe Albahari Avatar answered Oct 22 '22 09:10

Joe Albahari


Another solution, based on this comment in the LINQPad forum, is to do the following:

  1. Copy the System.Data.SQLite.dll file (and probably also the corresponding System.Data.SQLite.xml file too) somewhere, e.g. in the same directory as your LINQPad query file.
  2. Copy the x64 and x86 sub-directories, e.g. from the directory C:\Users\your-user-name-goes-here\AppData\Local\LINQPad\NuGet.FW46\System.Data.SQLite\System.Data.SQLite.Core.1.0.103\build\net46, to the same directory you copied the file in step [1].
  3. Add the following code to your LINQPad query:

    System.Environment.SetEnvironmentVariable(
        "PreLoadSQLite_BaseDirectory",
        @"C:\path\to\which\you\copied\the\files\and\directories\in\steps\one\and\two");
    

The advantage of this relative to the answer submitted by Joe Albahari (the creator of LINQPad by-the-way!) is that this could be readily included in a Git repo (were you to be storing your LINQPad query thusly).

like image 30
Kenny Evitt Avatar answered Oct 22 '22 10:10

Kenny Evitt