An attempt was made to load a program with an incorrect format
2016-10-08 11:28
441 查看
用.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.
相关文章推荐
- ASP.NET 解决An attempt was made to load a program with an incorrect format.问题
- BadImageFormatException or An attempt was made to load a program with an incorrect format
- An attempt was made to load a program with an incorrect format” even when the platforms are the same
- 64bit系统运行32位Web程序出现错误:An attempt was made to load a program with an incorrect format
- 解决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.
- Could not load file or assembly An attempt was made to load a program with an incorrect format.
- Could not load file or assembly ... 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 format. on Win7 64bit
- NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
- 关于an attempt was made to authenticate the locked user 的问题的想法
- was7.0 下面的错误WTRN0063E: An illegal attempt to commit a one phase capable resource with existing two phase
- Nginx启动报错:10013: An attempt was made to access a socket in a way forbidden
- Nginx启动报错:10013: An attempt was made to access a socket in a way forbidden
- bind() to 0.0.0.0:443 failed (10013: An attempt was made to access a socket in a way forbidden by it
- An application has made an attempt to load the C runtime library incorrectly.
- Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made
- java.lang.Exception: Socket bind failed: [730013] An attempt was made to acc
- tomcat警告解决办法:WARNING: An attempt was made to authenticate the locked user
- An attempt was made to send an email when no email session has been established,SSIS用sql2008发邮件失败