Visual Studio C# - 未找到 SQLite.Interop.dll

2024-04-05

我目前正在尝试使用 Visual Studio 创建一个与 SQLite 一起使用的 C# 应用程序。我使用 NuGet 为我的程序安装了 SQLite,解决方案资源管理器中出现了三个引用(System.Data.SQLite、System.Data.SQLite.EF6、System.Data.SQLite.Linq)。

当我在 VS 中执行我的应用程序时,一切正常。但是,每当我发布它(使用 ClickOnce)并尝试运行该应用程序时,它都会崩溃并出现以下错误:System.DllNotFoundException:无法加载 DLL 'SQLite.Interop.dll':找不到指定的模块(来自 HRESULT 的异常:0x8007007E)

经过一番研究,我在 Debug 文件夹中找到了这个 dll,并将其复制到创建程序的“.exe”版本的文件夹中(在发布并执行“setup.exe”之后)。这样,应用程序就可以正常运行了。

但我对这个解决方案并不是很满意,因为它看起来真的很脏。我不希望未来的用户在安装我的应用程序时必须手动执行此操作!

因此,我的问题是:我该怎么做才能确保这个 dll 与我的程序一起安装?

注意:我尝试了这篇文章的第一个答案:无法加载dll sqlite interop dll WPF https://stackoverflow.com/questions/27678554/unable-to-load-dll-sqlite-interop-dll-wpf但我似乎不适合我。


我在Visual Studio 2017和.NET Framework 4.5的环境中也遇到了类似的问题,情况是:

我正在开发一个 Outlook 插件,使用 ClickOnce 来发布它,并使用 SQLite 作为数据库。从 NuGet 将 SQLite 库安装到项目中后,它在本地环境中完美运行,但在客户端计算机上弹出异常错误消息“无法加载 DLL 'SQLite.Interop.dll'”。

I compared the two environments and found the DLL file 'SQLite.Interop.dll' had not been published to the client machine that we can see in the following graphic. enter image description here

I searched 'SQLite.Interop.dll' in local environment and found it is saved in the following folder "{project}\packages\System.Data.SQLite.Core.1.0.105.2\build\" for the specific .Net FrameWork enter image description here

So, my solution is adding these two DLL libraries into the project, then they can be published to the client machine using the ClickOnce. enter image description here

(注意:所选的DLL版本应与您环境中的NET Framework版本相同。)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Visual Studio C# - 未找到 SQLite.Interop.dll 的相关文章

随机推荐