An attempt was made to load a program with an incorrect format
用.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 CORFLAGS 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.
An attempt was made to load a program with an incorrect format的更多相关文章
- (C#) System.BadImageFormatException: An attempt was made to load a program with an incorrect format.
ASP.NET: System.BadImageFormatException: An attempt was made to load a program with an incorrect for ...
- Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
I have installed a Web application on IIS 7.0 windows server 2008 R2 64 bit OS I am refering a oracl ...
- IISExpress运行网站时,Service Fabric报Could not load file or assembly 'Microsoft.ServiceFabric.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format.
打开VS TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS,选中 "Use the 64 bit vers ...
- Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program
今天同事在一个服务器(winserver 2008 x64)上新建了一个IIS(7) 网站,但是报了如下错误: Could not load file or assembly 'System.Data ...
- hive sequencefile导入文件遇到FAILED: SemanticException Unable to load data to destination table. Error: The file that you are trying to load does not match the file format of the destination table.错误
hive sequencefile导入文件遇到FAILED: SemanticException Unable to load data to destination table. Error: Th ...
- error_Could not load file or assembly
原文链接 Could you be missing the loaded assembly from your configuration file? Ensure you have somethin ...
- Unhandled Exception: System.BadImageFormatException: Could not load file or assembly (2008R2配置x64website)
.NET Error Message: Unhandled Exception: System.BadImageFormatException: Could not load file or asse ...
- SystemErrorCodes
有人把SystemErrorCodes整理成了类,并定义了方法,用于返回消息,他大概不知道FormatMessage的用法,放在这里做参考吧 C# code snipppet class System ...
- System Error Codes
很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...
随机推荐
- 在GitHub上建立个人主页的方法
GitHub就不需要介绍了,不清楚可以百度一下.只说目前GitHub是最火的开源程序托管集中地了,连PHP的源码都在GitHub上面托管了(https://github.com/php ). GitH ...
- Python笔记 001
#python版本:3.5.2 #for循环 for letter in ("xuyingke"): #默认循环 print ("当前字母:",letter) ...
- [cyber security][php]pfSense目录遍历漏洞分析
0×00 导言 pfSense是一个基于FreeBSD,专为防火墙和路由器功能定制的开源版本. 在本文中,我们将向大家介绍在pfSense的2.1.3以及更低版本中的CVE-2014-4690漏洞:对 ...
- day17算法
http://www.360doc.com/content/14/0804/11/1073512_399302715.shtml
- (转)WHY DEEP LEARNING IS SUDDENLY CHANGING YOUR LIFE
Main Menu Fortune.com E-mail Tweet Facebook Linkedin Share icons By Roger Parloff Illustration ...
- Mabitis 多表查询(一)resultType=“java.util.hashMap”
1.进行单表查询的时候,xml标签的写法如下 进行多表查询,且无确定返回类型时 xml标签写法如下: <select id="Volume" parameterType=&q ...
- Java 学习总结(一)
1. 概述 1.1 dos命令行--常见的命令 l dir : 列出当前目录下的文件以及文件夹 l md : 创建目录 l rd : 删除目录 l cd : 进入指 ...
- 1、java中常用名字规范
包名:多个单词组成是所有单词字母小写. 类名.接口名:所有单词首字母大写. 变量名.函数名:多单词组成时第一个单词首字母小写,从第二个单词开始首字母大写. 常量名:所有字母大写,单词之间用 “_” 连 ...
- SilverlightERP&CRM源码(可用于开发基于Silverlight的CRM,OA,HR,进销存等)
SilverlightERP系统源代码(支持创建OA.SilverlightCRM.HR.进销存.财务等系统之用) 可用于开发以下系统 SilverlightERP SilverlightCRM Si ...
- grunt集成自动启动
Grunt可以执行像压缩, 编译, 单元测试, 代码检查以及打包发布的任务. 本文介绍使用Grunt实现nodejs程序自启动功能. 目录: Grunt介绍 Grunt安装 Grunt使用 Grunt ...