构造 System.Data.SQLite.SQLiteConnection 时导致 System.BadImageFormatException 的原因

发布于 2024-08-17 13:10:07 字数 469 浏览 3 评论 0原文

我已将代码分解为尽可能小的语句:

Dim cn As System.Data.SQLite.SQLiteConnection

从 WinForm 应用程序调用代码时出现以下错误:

System.BadImageFormatException:可以 不加载文件或程序集 'System.Data.SQLite,版本=1.0.65.0, 文化=中立, PublicKeyToken=db937bc2d44ff139' 或 它的依赖项之一。一次尝试 被用来加载一个程序 格式不正确。文件名: 'System.Data.SQLite,版本=1.0.65.0, 文化=中立, PublicKeyToken=db937bc2d44ff139'

然而,从 MS Unit Test 调用同一段代码我没有收到错误,而且完整的代码集按预期工作。

I've broken the code down to the smallest possible statement:

Dim cn As System.Data.SQLite.SQLiteConnection

And I get the following error when calling the code from a WinForm applicaiton:

System.BadImageFormatException: Could
not load file or assembly
'System.Data.SQLite, Version=1.0.65.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format. File name:
'System.Data.SQLite, Version=1.0.65.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139'

Yet calling the same piece of code from MS Unit Test I do not get the error, plus the full code set works as expected.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转瞬即逝 2024-08-24 13:10:07

SQLite 包含非托管代码,除非部署 64 位版本,否则无法在 64 位操作系统上运行它。快速修复:项目 + 属性,构建选项卡,平台目标 = x86。

SQLite contains unmanaged code, you can't run it on a 64-bit operating system unless you deploy the 64-bit version. Quick fix: Project + Properties, Build tab, Platform Target = x86.

羅雙樹 2024-08-24 13:10:07

确保针对 32 位和 64 位使用正确的汇编。

Make sure you use correct assembly with respect to 32 and 64 bits.

梨涡少年 2024-08-24 13:10:07

我通过 NuGet 下载新版本的 SQLite DLL 解决了这个问题:
http://gurustop.net/博客/2011/05/19/sqlite-database-nuget-package-common-problems-solved/

I solved the problem by downloading a new version of the SQLite DLL via NuGet:
http://gurustop.net/blog/2011/05/19/sqlite-database-nuget-package-common-problems-solved/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文