为什么我的 WPF 应用程序中出现“无法加载 DLL 'sqlite3'”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27328490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:46:35  来源:igfitidea点击:

Why am I getting "Unable to load DLL 'sqlite3'" in my WPF app?

wpfsqlitevisual-studio-2013nugetgalleryruntime-packages

提问by B. Clay Shannon

I added what I thought were the necessary SQLite (and sqlite-net) packages to my app. On running it, though, I get an exception:

我在我的应用程序中添加了我认为必要的 SQLite(和 sqlite-net)包。但是,在运行它时,我得到了一个例外:

System.DllNotFoundException was unhandled by user code HResult=-2146233052 Message=Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from

System.DllNotFoundException 未由用户代码处理 HResult=-2146233052 消息=无法加载 DLL 'sqlite3':找不到指定的模块。(例外来自

I have the following SQLite packages installed:

我安装了以下 SQLite 包:

enter image description here

在此处输入图片说明

What is missing?

有什么不见了?

UPDATE

更新

I tried ajawad987's suggestion, but still get the same runtime error, even though I've got this:

我尝试了 ajawad987 的建议,但仍然得到相同的运行时错误,即使我有这个:

enter image description here

在此处输入图片说明

...and this:

...和这个:

enter image description here

在此处输入图片说明

UPDATE 2

更新 2

Where this runtime exception takes place (in SQLite.cs) seems odd to me:

这个运行时异常发生的地方(在 SQLite.cs 中)对我来说似乎很奇怪:

if SILVERLIGHT || USE_CSHARP_SQLITE

如果银光 || USE_CSHARP_SQLITE

        var r = SQLite3.Open (databasePath, out handle, (int)openFlags, IntPtr.Zero);

else

别的

        // open using the byte[]
        // in the case where the path may include Unicode
        // force open to using UTF-8 using sqlite3_open_v2
        var databasePathAsBytes = GetNullTerminatedUtf8 (DatabasePath);
        var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);

endif

万一

But I amusing C#, so why is the line that's failing even running? (it fails in the "else" block)?

但是,我正在使用C#,那么,为什么行未能真实甚至运行?(它在“else”块中失败)?

回答by ajawad987

Is your project build set to Any CPU? You'll need to set it to either x86or x64for SQLite3. The x86route will yield more compatibility across devices, so I recommend that option unless your doing some specific 64-bit stuff.

您的项目构建设置为Any CPU? 您需要将其设置为 SQLite3x86x64SQLite3。该x86路由将产生更多的跨设备兼容性,因此除非您执行某些特定的 64 位操作,否则我建议使用该选项。

Edit: You'll also need to download the actual Sqlite DLL manually from Sqlite's main site. The file you want is named sqlite-dll-win32-x86-3080702.zip. Extract the DLL from that ZIP and add it to your project as a content file. Set the copy to output directory option in the properties tool window to Copy Always, and rebuild. Also ensure that your project is set to the x86 option as mentioned above.

编辑:您还需要从Sqlite 的主站点手动下载实际的 Sqlite DLL 。您想要的文件名为sqlite-dll-win32-x86-3080702.zip. 从该 ZIP 中提取 DLL 并将其作为内容文件添加到您的项目中。将属性工具窗口中的复制到输出目录选项设置为始终复制,然后重建。还要确保您的项目设置为如上所述的 x86 选项。

This should hopefullydo the trick... its been a while since I've used Sqlite in a .NET application.

希望这应该能解决问题......自从我在 .NET 应用程序中使用 Sqlite 已经有一段时间了。

Side Notes: The Nuget package you downloaded actually only contains the C# wrapper library around the real Sqlite DLL.

旁注:您下载的 Nuget 包实际上只包含围绕真实 Sqlite DLL 的 C# 包装库。

回答by CFL

I had the same problem on a windows store app and i solved it by following this tutorial : http://www.c-sharpcorner.com/UploadFile/d351ba/working-with-sqlite-in-windows-store-apps/

我在 Windows 商店应用程序上遇到了同样的问题,我按照本教程解决了这个问题:http: //www.c-sharpcorner.com/UploadFile/d351ba/working-with-sqlite-in-windows-store-apps/

No need to download manually the dll. The important step is the fifth :

无需手动下载dll。重要的步骤是第五步:

5. Add references to the project.

5. 添加对项目的引用。

Right-click on the References to the project under solution, select Add References. This opens up the Reference Manager of the project.

右键单击解决方案下的项目引用,选择添加引用。这将打开项目的参考管理器。

In the Reference Manager click on Windows Version. My application targets Windows 8.1 and therefore I have selected “Windows 8.1”. Select Extensions from the list as shown in the preceding screen shot. Now you will get the list of SDKs applicable to your project. As could be seen in the screen, SQLite for Windows Runtime (Windows 8.1) is available in the list post installation of SQLite from NuGet Package Installer.

在参考管理器中单击 Windows 版本。我的应用程序面向 Windows 8.1,因此我选择了“Windows 8.1”。从列表中选择扩展,如前面的屏幕截图所示。现在您将获得适用于您的项目的 SDK 列表。从屏幕中可以看出,适用于 Windows 运行时 (Windows 8.1) 的 SQLite 可从 NuGet 包安装程序安装 SQLite 后的列表中获得。

Now check/tick the two options Microsoft Visual C++ 2013 Runtime Package for Windows 8.1 and SQLite for Windows Runtime (Windows 8.1) as shown in the screen shot. Then click “Ok”.

现在检查/勾选两个选项 Microsoft Visual C++ 2013 Runtime Package for Windows 8.1 和 SQLite for Windows Runtime (Windows 8.1),如屏幕截图所示。然后点击“确定”。

Check whether or not the references are added. You can see references are added but it is showing an exclamatory mark on these added references. If you build the application now you will get some warning messages along with the error messages in all certainty and the build fails with some messages as shown below. This is because the SQLite we have installed will not support the “Any CPU” processor architecture.

检查是否添加了引用。您可以看到添加了引用,但在这些添加的引用上显示了感叹号。如果您现在构建应用程序,您肯定会收到一些警告消息和错误消息,并且构建失败并显示一些消息,如下所示。这是因为我们安装的 SQLite 不支持“Any CPU”处理器架构。

Now change the target platform from “Any CPU” to your CPU Architecture. In my case, the CPU Architecture is x64. The procedure to check your CPU architecture is specified below.

现在将目标平台从“任何 CPU”更改为您的 CPU 架构。就我而言,CPU 架构是 x64。下面指定了检查 CPU 架构的过程。

Not sure if this work for WPF app, but it worked for me on Windows store app. Click the link above for details and screenshots.

不确定这是否适用于 WPF 应用程序,但它适用于 Windows 商店应用程序。单击上面的链接以获取详细信息和屏幕截图。

Hope this will help some people ;-)

希望这会帮助一些人;-)

回答by DDst

In my case I just had to set project build to x86or x64ANDset the target framework to 4. It doesn′t work with a higher framework.

就我而言,我只需将项目构建设置为x86x64 并将目标框架设置为 4。它不适用于更高的框架。