定期我得到以下异常:

无法加载DLL 'SQLite.Interop.dll':无法找到指定的模块。(异常来自HRESULT: 0x8007007E)

我使用的是1.0.82.0。在VS2010, Win7 64操作系统下使用nuget安装。

一旦异常开始出现,它就会不断出现——在调试和发布中,在VS内部或外部运行应用程序。

阻止它的唯一方法就是退出并重新登录。不抛出异常并加载dll。 它可以工作几天,但之后又会坏掉。

有人见过这样的情况吗,有解决方案吗?


当前回答

复制SQLite.Interop.dll到项目目录。

src\
  project\
      bin\   <-- Past in bin
         x64\
           SQLite.Interop.dll <-- Copy this if 64
         x86\
           SQLite.Interop.dll <-- Copy this if 32

其他回答

I got the same problem. However, finally, I can fix it. Currently, I use Visual Studio 2013 Community Edition. I just use Add->Existing Item... and browse to where the SQLite.Data.SQLite files are in (my case is 'C:\Program Files (x86)\System.Data.SQLite\2013\bin'). Please don't forget to change type of what you will include to Assembly Files (*.dll; *.pdb). Choose 'SQLite.Interop.dll' in that folder. From there and then, I can continue without any problems at all. Good luck to you all. ^_^ P.S. I create web form application. I haven't tried in window form application or others yet.

如果您下载了正确的SQLite二进制文件,则根据项目构建选项将SQLite. interop .dll复制到您的发布或调试文件夹中。

我在多个项目的解决方案中遇到了类似的问题。SQLite.Interop.dll对于使用ClickOnce随软件发布的一个插件是必要的。

在visual studio中调试一切正常,但是部署的版本缺少包含DLL的文件夹x86/和x64/。

使用ClickOnce让它在部署后工作的解决方案是在解决方案的启动项目(也是正在发布的项目)中创建这两个子文件夹,将dll复制到其中,并将它们设置为Content copy Always。

通过这种方式,ClickOnce发布工具自动将这些文件和文件夹包含在清单中,并使用它们部署软件

这里确实有很多答案,但我的答案简单明了,没有gac。

问题是,可执行文件需要一个正确的SQLite.Interop.dll (x86或x64)的副本来访问我们的数据库。

大多数架构都有层,在我的例子中,数据层有SQLite连接所需的DLL。

所以我简单地把一个后构建脚本到我的数据层解决方案和一切工作良好。


TL; diana;

在构建选项中将解决方案的所有项目设置为x86或x64。 使用SQLite nuget包将以下Post-Build-Script添加到项目中: /y . xcopy "$(TargetDir)x64" "$(SolutionDir)bin\Debug\

当然,您必须更改发布构建和x86构建的脚本。


STL; diana;

将SQLite.Interop.dll放在*.exe文件旁边。

来自NuGet的多体系结构(x86, x64)版本SQLite的默认安装显示了您所描述的行为。如果你想加载。net运行时选择在你的机器上运行你的应用程序的实际体系结构的正确版本,那么你可以给DLL加载器一个关于在哪里找到正确库的提示,如下所示:

在Program.Main()之前添加kernel32.dll函数调用SetDLLDirectory()的声明:

    [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)]
    [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
    static extern bool SetDllDirectory(string lpPathName);

然后使用您自己的方法确定正确的子目录,以找到'SQLite.Interop.dll'的特定于体系结构的版本。我使用以下代码:

    [STAThread]
    static void Main()
    {
        int wsize = IntPtr.Size;
        string libdir = (wsize == 4)?"x86":"x64";
        string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
        SetDllDirectory(System.IO.Path.Combine(appPath, libdir));