为什么我收到“无法加载 DLL 'sqlite3'"的消息?在我的 WPF 应用程序中? [英] Why am I getting "Unable to load DLL 'sqlite3'" in my WPF app?

查看:18
本文介绍了为什么我收到“无法加载 DLL 'sqlite3'"的消息?在我的 WPF 应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我安装了以下 SQLite 包:

I have the following SQLite packages installed:

缺少什么?

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

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

...还有这个:

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

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

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

其他

        // 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

但我使用 C#,那么为什么这条线甚至运行失败?(它在else"块中失败)?

endif

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

推荐答案

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

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

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

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.

这应该希望可以解决问题……我已经有一段时间没有在 .NET 应用程序中使用 Sqlite.

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

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

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

这篇关于为什么我收到“无法加载 DLL 'sqlite3'"的消息?在我的 WPF 应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆