Visual Studio C# - 找不到 SQLite.Interop.dll [英] Visual Studio C# - SQLite.Interop.dll not found

查看:30
本文介绍了Visual Studio C# - 找不到 SQLite.Interop.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently trying to create with Visual Studio a C# application working with SQLite. I installed SQLite for my program with NuGet and three references appeared in the Solution Explorer (System.Data.SQLite, System.Data.SQLite.EF6, System.Data.SQLite.Linq).

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

When I execute my app in VS, everything works fine. However, whenever I publish it (with ClickOnce) and try to run the app, it crashes with the following error : System.DllNotFoundException : Unable to load DLL 'SQLite.Interop.dll' : the specified module cannot be found (Exception from HRESULT : 0x8007007E)

经过一番研究,我在 Debug 文件夹中找到了这个 dll 并将其复制到了.exe"所在的文件夹中.创建了我的程序的版本(在发布和执行setup.exe"之后).这样,应用程序运行良好.

After some research, I found this dll in the Debug folder and copied it in the folder where the ".exe" version of my program is created (after publishing and executing "setup.exe"). This way, the app runs well.

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

But I'm not really satisfied with this solution, since it seems really dirty. I don't want future users to have to do this manually when they install my app !

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

Therefore, my question is : What can I do to make sure that this dll is installed together with my program ?

注意:我尝试了这篇文章的第一个答案:无法加载 dll sqlite interop dll WPF但我似乎不适合我.

Note : I tried the first answer of this post : unable to load dll sqlite interop dll WPF But I didn't seem to work for me.

推荐答案

参见 使用本地库预加载,位于 https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

您可能需要在另一个 SQLite DLL 下包含 x86 和 x64 文件夹.

You likely need to include the x86 and x64 folders under the the other SQLite DLL.

我在下面添加了相关信息,以防上面的链接失效/更改.

I've added the relevant info below in case the above link ever dies/changes.

如果开发和客户机器可能有不同的处理器架构,可能需要多个二进制包.为了这情况下,使用原生库预加载功能是高度受到推崇的.它从 1.0.80.0 版开始可用并通过以下方式启用默认.为了利用这个特性,单独的托管和互操作程序集必须与 XCOPY 部署一起使用(即混合模式程序集不支持此功能,也不支持此功能)当程序集部署到全局程序集缓存时),结果在看起来像这样的应用程序部署中:

If the development and customer machines may have different processor architectures, more than one binary package may be required. For this situation, using the native library pre-loading feature is highly recommended. It is available as of version 1.0.80.0 and enabled by default. In order to take advantage of this feature, the separate managed and interop assemblies must be used with XCOPY deployment (i.e. this feature is not supported by the mixed-mode assembly, nor when the assembly is deployed to the global assembly cache), resulting in an application deployment that looks something like this:

  • binApp.exe(可选的,仅限托管的应用程序可执行文件组装)
  • binApp.dll(可选的,仅限托管的应用程序库组装)
  • binSystem.Data.SQLite.dll(必需的,仅托管核心组装)
  • binSystem.Data.SQLite.Linq.dll(可选,仅限托管LINQ 程序集)
  • binSystem.Data.SQLite.EF6.dll(可选,仅限托管的 EF6 程序集)
  • binx86SQLite.Interop.dll(必需,x86 本机互操作程序集)
  • binx64SQLite.Interop.dll(必需,x64 本机互操作程序集)
  • 上面的字符串bin"表示应用程序所在的目录二进制文件将部署在目标机器上.与原住民启用库预加载功能和应用程序部署如上所示,System.Data.SQLite 仅托管程序集将尝试自动检测当前处理器架构处理并预加载适当的本机库.

    The string "bin" above represents the directory where the application binaries are to be deployed on the target machine. With the native library pre-loading feature enabled and the application deployment shown above, the System.Data.SQLite managed-only assembly will attempt to automatically detect the processor architecture of the current process and pre-load the appropriate native library.

    这篇关于Visual Studio C# - 找不到 SQLite.Interop.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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