定期我得到以下异常:

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

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

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

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

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


当前回答

Mine didn't work for unit tests either, and for some reason Michael Bromley's answer involving DeploymentItem attribute didn't work. However, I got it working using test settings. In VS2013, add a new item to your solution and search for "settings" and select the "Test Settings" template file. Name it "SqliteUnitTests" or something and open it. Select "Deployment" off to the right, and add Directory/File. Add paths/directories to your SQLite.Interop.dll file. For me, I added two paths, one each for Project\bin\Debug\x64 and Console\bin\Debug\x86. You may also want to add your Sqlite file, depending on how you expect your unit test/solution to access the file.

其他回答

我在运行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目录。

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

旧项目文件格式

即以<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"/>

大会上会有竞争吗?检查DLL上是否有其他具有文件锁的应用程序。

如果是这个原因,使用Sysinternal的Process Explorer之类的工具来发现有问题的程序应该很容易。

HTH, 粘土

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

我在一个WPF项目中使用SQLite时遇到了同样的问题,该项目的平台目标是任意CPU。我通过以下步骤修复了它:

在Visual Studio中打开项目设计器。如何做到这一点的细节可以在这里找到。 单击Build选项卡。 禁用首选32位选项。

或者,您也可以将平台目标设置为x86或x64。我认为这个问题是由System.Data.SQLite库使用平台目标来获取'SQLite.Interop.dll'文件的位置引起的。

更新:

如果无法联系到项目设计人员,只需从文本编辑器中打开项目(*.csproj)文件,并将值<Prefer32Bit>false</Prefer32Bit>添加到<PropertyGroup>…< / PropertyGroup >标记。

示例代码

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>[Set by Visual Studio]</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>[Set by Visual Studio]</RootNamespace>
    <AssemblyName>[Set by Visual Studio]</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>[Set by Visual Studio]</FileAlignment>
    <!--Add the line below to your project file. Leave everything else untouched-->
    <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>