zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    如何使用BackgroundWorker
    Start SQL Service failed with message: "the log scan number passed to log scan in database 'master' is not valid"
    Cmdkey 凭证管理器工具
    PowerShell根据下载link下载文件
    vnc远程到连接linux服务器。
    shell远程取数据的脚本.
    about开源监控nagios.
    Android入门:File文件存储
    Android入门:Layout
    Android入门:Log介绍
  • 原文地址:https://www.cnblogs.com/time-is-life/p/5937908.html
Copyright © 2011-2022 走看看