博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
An attempt was made to load a program with an incorrect format
阅读量:6977 次
发布时间:2019-06-27

本文共 1492 字,大约阅读时间需要 4 分钟。

 

用.net调用一个C++ 32位的DLL, 编译的时候选择x86, 在部署到一个64位的机器上的时候报错:"An attempt was made to load a program with an incorrect format"

解决方法:

在出错的机器上,用VS命令行工具定位到.net exe所在的目录,然后运行

corflags <.net exe文件名> /32Bit+

 

参考文章如下:

 

 

Tip of the day: "An attempt was made to load a program with an incorrect format" .NET P/INVOKE issue

The other day I was using a 3rd party utility which was built on the .NET platform. My primary work computer happens to be a x64 installation. So on this computer when I fired the utility up, and tried to perform some tasks it would error with a .NET Exception which basically had the following characteristics:

– Message: "An attempt was made to load a program with an incorrect format"

– Exception: System.BadImageFormatException

After some troubleshooting it turned out that this utility was trying to load a plain-old DLL (which exported some functions) presumably using P/Invoke. The DLL was built for 32-bit platforms. Now it turns out that by design a 64-bit process (the 3rd party utility would run as a 64-bit process owing to the 64-bit .NET runtime) would be prevented from loading a non-COM 32-bit DLL (32-bit COM DLLs are loaded in a DLLHOST.EXE surrogate when invoked from a 64-bit client process, BTW…) with the above exception.

To configure the utility to run as a 32-bit .NET process, it turns out you can use the  utility. You run it as follows to switch the 32-bit execution mode ON:

corflags utility.exe /32Bit+

To turn it off, just use /32Bit- in the above command line.

转载地址:http://bmupl.baihongyu.com/

你可能感兴趣的文章
expect
查看>>
Could not create the view: An unexpected exception was thrown. Myeclipse空间报错
查看>>
RHEL6入门系列之九,常用命令2
查看>>
LINUX新手入门-1.装系统
查看>>
Attach Volume 操作(Part II) - 每天5分钟玩转 OpenStack(54)
查看>>
puppet 初识
查看>>
rsync
查看>>
ubuntu安装redis的方法以及PHP安装redis扩展、CI框架sess使用redis的方法
查看>>
功能演示:戴尔PowerConnect 8024交换机VLAN的创建与删除
查看>>
SharePoint运行状况分析器有关磁盘空间不足的警告
查看>>
Oracle的分页查询
查看>>
Objective-C非正式协议与正式协议
查看>>
jquery mobie导致超链接不可用
查看>>
Python OpenCV学习笔记之:图像读取,显示及保存
查看>>
计算机职业目标
查看>>
2月国内搜索市场:360继续上升 百度下降0.62%
查看>>
HTML样式offset[Direction] 和 style.[direction]的区别
查看>>
使用memcache做web缓存
查看>>
我的友情链接
查看>>
我的友情链接
查看>>