定期我得到以下异常:

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

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

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

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

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


当前回答

将x86和x64的“SQLite.Interop.dll”文件复制到调试文件夹中。这些文件应该复制到调试文件夹中的“x86”和“x64”文件夹中。

其他回答

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

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

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

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

我有这个问题,因为Visual c++ 2010可重分发没有安装在我的电脑。如果你还没有安装Visual c++ 2010 redistributable,下载并安装这个(检查x86或64 dll)。

来自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));

我的情况有点特殊。我在docker容器中运行一个应用程序,并不断得到以下错误

系统。DllNotFoundException:无法加载共享库'SQLite.Interop.dll'或其依赖项之一为了帮助诊断加载问题,可以考虑设置LD_DEBUG环境变量:libSQLite.Interop.dll:不能打开共享目标文件:没有这样的文件或目录

因此,我设置LD_DEBUG=libs,以找出System.Data.SQLite.dll正在查找的文件夹,以查找SQLite.Interop.dll。

你可以在这里找到关于设置LD_DEBUG的信息:http://www.bnikolic.co.uk/blog/linux-ld-debug.html

一旦我这样做了,我意识到SQLite.Interop.dll被找到了。没有找到的DLL是libSQLite.Interop.dll。我应该阅读整个错误消息。

在谷歌上搜索了几个小时后,我找到了这个关于如何从SQLite源代码编译缺失DLL的指南。

注意,实际丢失的文件是libSQLite.Interop.dll.so

编译源代码时,你会得到libsqlite。interop。so,你需要将它重命名为libsqlite。interop。dll。so,然后将它放到它要找的目录中你可以通过设置LD_DEBUG找到它。

对我来说,System.Data.SQLite.dll查找的目录是/usr/lib/x86_64-linux-gnu/

所以,我的问题是SQLite试图在WPF的设计时加载。由于我只关心x86环境,所以我将CPU首选项设置为x86环境,并将Nuget包中的SQLite.Interop.dll复制到解决方案的根目录。重新启动解决方案,所有问题都消失了。因此,如果遇到设计时问题,请将库放到解决方案的根目录中。

此外,我在运行时遇到了类似的问题,所以我必须将SQLite.Interop.dll的副本放入我的项目中,并将其设置为复制,如果它在属性中较新的。似乎x86和x64提供的文件夹是完全无用的。还需要进一步的调查,但总的来说…在你的项目中手动引用SQLite比使用Nuget包更容易。

此外,官方常见问题解答如下:

(20) When the System.Data.SQLite project is compiled and run from inside Visual Studio, why do I get a DllNotFoundException or a BadImageFormatException (for "sqlite3.dll" or "SQLite.Interop.dll") when trying to run or debug the application? When compiling and running a solution from within Visual Studio that uses the System.Data.SQLite project (including the test project), it is very important to select the correct build configuration and platform. First, managed applications to be debugged inside Visual Studio cannot use the mixed-mode assembly (i.e. because it is always compiled to the platform-specific build output directory). This is necessary to properly support building binaries for multiple platforms using the same source project files. Therefore, only the "DebugNativeOnly" or "ReleaseNativeOnly" build configurations should be selected when running a managed application from inside Visual Studio that relies upon the System.Data.SQLite assembly. These build configurations contain a custom post-build step that copies the required native assembly to the managed output directory (i.e. to enable running the managed binaries in-place). However, this post-build step will only be performed if the selected platform matches that of the operating system (e.g. "Win32" for 32-bit Windows and "x64" for 64-bit Windows). Therefore, it is good practice to double-check the selected build platform against the operating system prior to attempting to run a managed project in the solution.

https://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q20