定期我得到以下异常:

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

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

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

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

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


当前回答

我想到了一个解决办法。

在我的例子中,我使用的是Microsoft Visual Studio安装程序项目。 安装项目看不到来自主要输出的x64和x86文件夹和内容。

解决方案:

将x64和x86文件夹都添加到安装程序中的应用程序文件夹中。 添加两个文件夹的内容。

这将允许安装程序复制SQLite工作所需的DLL文件。

其他回答

旧项目文件格式

即以<Project ToolsVersion="3.5" DefaultTargets="Build"开头的项目xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

将以下内容添加到“主”/根项目的csproj中

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

新的SDK项目文件格式

例如,以<Project Sdk="Microsoft.NET.Sdk.*"开头的项目>

将PrivateAssets="none"添加到System.Data.Sqlite PackageImport依赖链中的每个ProjectReference/PackageImport

ex:

<PackageReference Include="System.Data.SQLite.Core" Version="1.0.110" PrivateAssets="none"/>

我正在做一个简单的控制台应用程序,向SQLite数据库添加一些测试数据,并得到这个错误。项目的配置是“Any CPU”。我通过将SQLite.Interop.dll复制到bin\debug文件夹来修复它。更好的方法是使用@Wil的方法,但是如何为“任何CPU”配置指定该方法呢?

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.

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

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

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

(唷!)

你需要通过NuGet安装System.Data.SQLite.Core。 如果您使用InnoSetup,请确保在.iss文件的[Files]部分中有以下行:

Source: "C:\YourProjectPath\bin\Release\x64\*"; DestDir: "{app}\x64"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\YourProjectPath\bin\Release\x86\*"; DestDir: "{app}\x86"; Flags: ignoreversion recursesubdirs createallsubdirs

更改项目的路径“YourProjectPath”。