定期我得到以下异常:

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

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

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

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

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


当前回答

我不知道这是否是一个好的答案,但我能够通过在AppDomain下以“本地系统”的身份运行我的应用程序来解决这个问题。

其他回答

我在一个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>

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

超过30个答案,但我用了不同的方法。

我有两个独立的项目。一个Windows服务,和一个Windows窗体应用程序。应用程序引用WS项目,两者都引用SQLite核心nuget包。

在构建WS项目时,有x64和x32文件夹。但在构建应用程序时,文件夹不会显示出来。

检查这里的答案,我不能让他们工作。但是我发现WS项目中有以下代码片段,而App项目中没有。我添加了它,现在文件夹显示正确。

<Import Project="..\packages\System.Data.SQLite.Core.1.0.112.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.112.0\build\net46\System.Data.SQLite.Core.targets')" />

旧项目文件格式

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

我在一个WebAPI/MVC5 web项目和一个特性测试项目的解决方案中遇到了这个问题,这两个项目都来自同一个数据访问(或“核心”)项目。像这里的许多人一样,我使用的是通过NuGet在Visual Studio 2013中下载的副本。

What I did, was in Visual Studio added a x86 and x64 solution folder to the Feature Test and Web Projects. I then did a Right Click | Add Existing Item..., and added the appropriate SQLite.interop.dll library from ..\SolutionFolder\packages\System.Data.SQLite.Core.1.0.94.0\build\net451\[appropriate architecture] for each of those folders. I then did a Right Click | Properties, and set Copy to Output Directory to Always Copy. The next time I needed to run my feature tests, the tests ran successfully.