定期我得到以下异常:

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

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

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

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

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


当前回答

我知道我来晚了,但在我今天下载了最新的x86/x64(版本1.0.88.0)后,我就遇到了这个问题。我在VS2012中的本地IIS默认运行32位,没有简单的方法切换到x64。我的生产服务器运行64位。

无论如何,我安装了NuGet包到一个DLL项目,我得到了这个错误。为了让它工作,我必须把它安装到主站点项目中。即使它根本不涉及SQLite类。

我的猜测是SQLite使用入口程序集来检测要加载哪个版本的Interop。

其他回答

一个对我有效的解决方案是从nuget包中安装System.Data.SQLite。

导入要导入的项目的.dll,并安装System.Data.SQLite。

这将安装与您的解决方案/项目兼容并更新的ddl。

我发现当我允许Nuget更新SQLite到1.0.115.5时,我的项目不再需要'SQLite. interop .dll'。

这对我来说很管用。

With Visual Studio open, search and install SQLite.Core via the NUGET Package manager. Go to Solution Explorer in VS, Right click your PROJECT NAME-->ADD-->NEW FOLDER Name the folder x64 Repeat the process and add folder and name it x86 Right click the x64 folder-->ADD-->EXISTING ITEM Then browse to the DEBUG FOLDER. You will find the x64 folder. Open it and select the "SQLite.Interop.dll" file then hit OK. Repeat step 5 for the x86 folder. Right click the DLL that you just added and select PROPERTIES. In the option Copy to Output Directory, choose Copy always. Repeat step 7 for both DLLs in x64 and x86 folder.

下次构建该项目并使用另一台计算机时,它应该可以正常工作。

因此,在添加了NuGet之后,部署不会复制Interops。你可以把这个添加到你的csproj文件中,它应该会修复这个行为:

 <PropertyGroup> 
    <ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
    <CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
    <CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
    <CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
 </PropertyGroup>

如果你看一下NuGet for SQLite的源代码,你可以看到这些具体在做什么。这允许我使用ASP进行部署。净的核心。

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