“试图加载格式不正确的程序"即使平台相同 [英] "An attempt was made to load a program with an incorrect format" even when the platforms are the same

查看:30
本文介绍了“试图加载格式不正确的程序"即使平台相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 64 位系统上的 32 位非托管 DLL 调用函数.我得到的是:

I'm calling functions from a 32-bit unmanaged DLL on a 64-bit system. What I get is:

BadImageFormatException:尝试加载格式不正确的程序.(来自 HRESULT 的异常:0x8007000B)

BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

起初,我将我的项目设置为 Any CPU 平台,因此我将它们都更改为 x86,但此错误仍然发生.这确实是我所知道的唯一解决方法.

At first, I had my projects set to the Any CPU platform, so I changed them both to x86, but this error is still occurring. That's really the only fix I know for this.

DLL 没有损坏或任何东西,因为我可以将它们与其他程序一起使用(我没有源代码).我想也许它没有找到依赖项,但我检查了一下,它们都在那里.另外,在这种情况下它不会抛出 DllNotFoundException 吗?

The DLLs aren't corrupt or anything, because I can use them with other programs (that I don't have the source to). I thought that perhaps it wasn't finding a dependency, but I checked and they're all there. Plus, wouldn't it throw a DllNotFoundException in that case?

我还能做什么?在您说改用 64 位非托管 DLL"之前,让我指出没有.;)

What else can I do? And before you say "Use a 64-bit unmanaged DLL instead," let me point out that there isn't one. ;)

推荐答案

不知何故,配置管理器中的 Build 复选框已取消选中我的可执行文件,因此它仍在使用旧的 Any CPU 运行建造.在我解决这个问题后,Visual Studio 抱怨它无法调试程序集,但通过重新启动解决了这个问题.

Somehow, the Build checkbox in the Configuration Manager had been unchecked for my executable, so it was still running with the old Any CPU build. After I fixed that, Visual Studio complained that it couldn't debug the assembly, but that was fixed with a restart.

这篇关于“试图加载格式不正确的程序"即使平台相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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