定期我得到以下异常:

无法加载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

其他回答

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.

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

所以,我的问题是SQLite试图在WPF的设计时加载。由于我只关心x86环境,所以我将CPU首选项设置为x86环境,并将Nuget包中的SQLite.Interop.dll复制到解决方案的根目录。重新启动解决方案,所有问题都消失了。因此,如果遇到设计时问题,请将库放到解决方案的根目录中。

此外,我在运行时遇到了类似的问题,所以我必须将SQLite.Interop.dll的副本放入我的项目中,并将其设置为复制,如果它在属性中较新的。似乎x86和x64提供的文件夹是完全无用的。还需要进一步的调查,但总的来说…在你的项目中手动引用SQLite比使用Nuget包更容易。

此外,官方常见问题解答如下:

(20) When the System.Data.SQLite project is compiled and run from inside Visual Studio, why do I get a DllNotFoundException or a BadImageFormatException (for "sqlite3.dll" or "SQLite.Interop.dll") when trying to run or debug the application? When compiling and running a solution from within Visual Studio that uses the System.Data.SQLite project (including the test project), it is very important to select the correct build configuration and platform. First, managed applications to be debugged inside Visual Studio cannot use the mixed-mode assembly (i.e. because it is always compiled to the platform-specific build output directory). This is necessary to properly support building binaries for multiple platforms using the same source project files. Therefore, only the "DebugNativeOnly" or "ReleaseNativeOnly" build configurations should be selected when running a managed application from inside Visual Studio that relies upon the System.Data.SQLite assembly. These build configurations contain a custom post-build step that copies the required native assembly to the managed output directory (i.e. to enable running the managed binaries in-place). However, this post-build step will only be performed if the selected platform matches that of the operating system (e.g. "Win32" for 32-bit Windows and "x64" for 64-bit Windows). Therefore, it is good practice to double-check the selected build platform against the operating system prior to attempting to run a managed project in the solution.

https://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q20

我已经开始使用Costura了。Fody可以打包(.net)程序集,并嵌入和预加载本地dll。这也有助于以后的分发,因为您可以发送一个文件。

Install Costura Fody from Nuget. In your C# project create a folder called costrua32. In there add any native dlls you which C# to load. Once you have added them to this folder. Click on the properties window and change build action to "Embedded Resource" Finally you need to amend the XML file called FodyWeavers.xml as follows. Here I am specifying load the sql dll first. (note you drop the .dll) Weavers Costura PreloadOrder SQLite.Interop tbb_debug tbb /PreloadOrder> /Costura /Weavers

这样做的好处是,您不必编写任何构建前或构建后事件,最终产品完全封装在一个较大的文件中。

即使这是一篇旧文章,我也想在这里分享我找到的解决方案: http://system.data.sqlite.org/index.html/info/54e52d4c6f

如果您不想读取所有问题,解决方案是将“msvcr100.dll”文件(可以在Windows\System32目录中找到)复制到与SQLite.Interop.dll相同的路径。

我建议阅读问题以了解原因,并在安装程序中包含该文件,但仅在错误发生时才安装它,我在安装程序选项中使其成为可选组件。

HTH, Formentz