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

淺唱寂寞╮ 提交于 2020-01-01 09:38:41

问题


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.


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/34816986/why-am-i-getting-dllnotfoundexception-when-adding-sqlite-nuget-package-to-linqpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!