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 ...
随机推荐
- Aspose Word模板使用总结
Aspose Word模板使用总结 1.创建word模版,使用MergeFeild绑定数据 新建一个Word文档,命名为Template.doc 注意:这里并不是输入"< ...
- Android 中Thread,Handler,Loop学习
1.先看一下最简单的进度条示例 EG: package com.sxz.android.thread; import java.util.concurrent.atomic.AtomicBoolean ...
- POJ 3176 简单DP
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16448 Accepted: 10957 Descrip ...
- Android——数据存储(课堂代码整理:SharedPreferences存储和手机内部文件存储)
layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- POJ 1094 (TopoSort)
http://poj.org/problem?id=1094 题意:该题题意明确,就是给定一组字母的大小关系判断他们是否能组成唯一的拓扑序列.是典型的拓扑排序,但输出格式上确有三种形式: 1.该字母序 ...
- 没接触C++之前与学习了C++之后的思想转变
我在学习C++之前学习了C,学习C是因为选修时觉得它比较神奇,当时以为学会了C就能纵横计算机领域. 之后听说C++更厉害.并且大多数我这样的男生都喜欢玩游戏,C++又是能编写大型游戏逻辑的语言.于是幻 ...
- kuangbin_MST C (POJ 2031)
全程double精度就能过了 间接0距离不用管 prim自动连起来的 G++交的话只能用%f输出 C++的话加不加l都可以 (这么说以后用%f肯定不会错咯) 不过我不懂为什么他们的空间时间差了好多倍. ...
- Unity3d 引擎原理详细介绍
体系结构 为了更好地理解游戏的软件架构和对象模型,它获得更好的外观仅有一名Unity3D的游戏引擎和编辑器是非常有用的,它的主要原则. Unity3D 引擎 Unity3D的是一个屡获殊荣的工具,用于 ...
- Unity3D研究院之获取摄像机的视口区域
摄像机分为两种,一种是正交摄像机还有一种是透视摄像机.正交摄像机无论远近它的视口范围永远是固定的,但是透视摄像机是由原点向外扩散性发射,也就是距离越远它的视口区域也就越大.那么我们如何获取距离摄像机任 ...
- sp_change_users_login解决孤立用户问题
孤立帐户,指的是某个数据库的帐户只有用户名而没有登录名,这样的用户在用户库的sysusers系统表中存在,而在master数据库的syslogins中却没有对应的记录. 孤立帐户的产生一般是一下两种: ...