定期我得到以下异常:

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

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

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

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

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


当前回答

I don't know why this has not been included yet, but I had to do the research and find this out for myself, so hopefully someone will find this answer and be saved the trouble. This was for a WPF app. It worked fine on my Dev box, but did not work on the computer where I was copying it and got the Unable to load DLL 'SQLite.Interop.dll' error. I ported over all of its associated directories and files, directly from my "Debug" folder to this other computer when I got the same error as the OP when I ran it. My "bin" folder that contained my DLLs had been copied to "Debug\bin" and all were included, along with my application files when I did my copying to the other computer using this path, so it was not missing any files.

我在其他答案中看到的不适用的东西:

I did not use the NuGet package or need to create x86 or x64 folders that it seems that NuGet package creates. My DLLs (System.Data.SQLite and SQLite.Interop.dll, along with System.Data.SQLite.config) are in the "bin" folder in my project and were copied in manually (create "bin" folder in Solution Explorer in VS, paste DLLs into this folder in Windows Explorer, use Add > Existing Item to bring files into VS folder/project). Then I reference them as Referenced Assemblies in my project using that location ("References" > "Add Reference", and browse to one, rinse, repeat for the rest). This ensures my project knows exactly where they are. I did not need to reference any SQLite DLL file in my app.config or even touch my MyProject.csproj file. I did not even need to specify a particular processor! My project's build is for "Any CPU", even though I have only mixed or 64-bit DLLs and will only be running on Windows 7+, which are 64-bit OSes. (no x86-only/32-bit solely DLLs) I was already specifying them as "Content" and "copy if newer" for these DLLs when I experienced the OP's error.

我从https://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q20上找到了这个:

(11) Why do I get a DllNotFoundException (for "sqlite3.dll" or "SQLite.Interop.dll") when trying to run my application? Either the named dynamic link library (DLL) cannot be located or it cannot be loaded due to missing dependencies. Make sure the named dynamic link library is located in the application directory or a directory along the system PATH and try again. Also, be sure the necessary Visual C++ runtime redistributable has been installed unless you are using a dynamic link library that was built statically linked to it.

我要强调这段内粗体的部分。目标计算机是新的,除了. net 4.0之外没有加载任何程序。一旦我安装了c++,它就能够完成SQLite的命令。这应该是第一个常见问题之一,也是先决条件的一部分,但它被埋在了第11位。我的开发计算机已经加载了它,因为它带有Visual Studio,所以这就是它在那里工作的原因。

下载: Visual c++ Redistributable for Visual Studio 2015 https://www.microsoft.com/en-us/download/details.aspx?id=48145

更新3(累积更新): https://www.microsoft.com/en-us/download/details.aspx?id=53587

其他回答

因为这个问题的复杂性,我想在这里发表。我的解决方案是回滚到。net 4.0。我已经测试了3天了,还不能让System.Data.SQLite.Core.1.0.98.0与. net 4.5或. net 4.5.1一起工作。

测试在3台计算机、2台服务器和一台开发PC上进行。我还没能找到问题的根源。我已经尝试编辑.vsproj文件。我已经将SQLite.interop.dll添加到所有文件夹中。我已经将包应用到所有GAC文件夹,并单独删除和重新应用。最终删除。

我有System.Data.SQLite.Core.1.0.98.0与。net 4.0一起工作。我打算继续尝试迁移,但我想我会先开始一个新项目,看看我是否能让它以那种方式工作。它最初是一个。net 3.5 web应用程序,在我的旅行中,我发现大量的信息仍然引用了这个框架。

我在运行Visual Studio Express 2013时也遇到了同样的问题。我尝试了这里和其他地方提到的几种解决方案,但都没有用。我希望这个修正能帮助到其他人。

我通过在测试基于sqlite的服务的测试类上使用deploymenttem属性来修复它。

例子:

[TestClass]
[DeploymentItem(@"x86\SQLite.Interop.dll", "x86")] // this is the key
public class LocalStoreServiceTests
{

    [TestMethod]
    public void SomeTestThatWasFailing_DueToThisVeryIssue()
    {
         // ... test code here
    }
}

这将导致所需的SQLite.Interop.dll被复制到适当的“TestResults”文件夹中的x86目录。

全是绿色的。一切都很好。

我自己也遇到过这个问题,但事实证明是另一个原因:

System.DllNotFoundException was caught 
Unable to load DLL 'SQLite.Interop.dll': Access is denied. 

在这种情况下,代码是从IIS托管的web服务(为x86版本配置)中(间接地)调用的。我最终在IIS的应用程序池中找到了它:最初我使用的是“ASP。NET V4.0集成”(这导致了这个错误),但当我把它改成“DefaultAppPool”时,问题就消失了。

(唷!)

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.

扩展Kugel的回答,这对我来说是有效的(VS2015 Enterprise),利用dll中的SQLite,可以在构建和测试后从主项目中删除Nuget包:

1.安装Nuget包到主项目。

Install-Package System.Data.SQLite

2.构建应用程序并测试Sqlite连接是否正常工作:

select * from sqlite_master

3.从主版本卸载Nuget包。

UnInstall-Package System.Data.SQLite

4.手动删除SQLite和EntityFramework的dll引用:

System.Data.SQLite
System.Data.SQLite.EF6
System.Data.SQLite.Linq

从主项目的“包”中删除Xml引用。配置”XML文件。

这对我来说很有效,使我的项目保持干净。