zoukankan      html  css  js  c++  java
  • 问题解决!!! 无法启动服务.System.BadImageFormatException: 不是有效的 Win32 应用程序.

    无法启动服务.System.BadImageFormatException:  不是有效的 Win32 应用程序.

    OK 看描红位置。。。使用64位系统的童鞋应该知道怎么回事了吧?

     

     

    Visual Studio 64位应用程序编译

    Visual Studio的编译选项 build下的platform有X64、Any CPU和x86。X86表示只能在32位环境下运行,X64表示只能在64位环境下运行,Any CPU表示你的程序集可以根据环境变化适应32位还是64位,但是如果你的程序集依赖于一个x86选项编译的程序集,哪么你的程序集只能选择X86进行编译,而不能选择Any CPU编译,如果使用Any CPU编译,运行就会出现如下的错误:

       Unhandled Exception: System.BadImageFormatException: Could not load file or asse
    mbly 'SourceCode.HostClientAPI, Version=4.0.0.0, Culture=neutral, PublicKeyToken
    =16a2c5aaaa1b130d' or one of its dependencies. An attempt was made to load a pro
    gram with an incorrect format.
    File name: 'SourceCode.HostClientAPI, Version=4.0.0.0, Culture=neutral, PublicKe
    yToken=16a2c5aaaa1b130d'

    原因是如果用Any CPU编译,那么在64位机器默认的运行就是64位的,通常这情况十assembly需要调用一个32的COM库,只要用x86编译,那么程序就是以32位的程序,依靠wow64来运行的,就可以在64位系统上运行。所以,如果assembly需要使用win32库的话,那么编译选项就不能使用默认的Any CPU就需要注意了。

    如果你的程序集还有调用VC++编写的程序集,如果没有安装Microsoft Visual C++ 2005/2008/SP1 Redistributable Package (x86)更新包,还会出现类似的错误:

    Unhandled Exception: System.IO.FileLoadException: Could not load file or assembl

    y 'SourceCode.HostClientAPI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=16

    a2c5aaaa1b130d' or one of its dependencies. The application has failed to start

    because its side-by-side configuration is incorrect. Please see the application

    event log or use the command-line sxstrace.exe tool for more detail. (Exception

    from HRESULT: 0x800736B1)

    File name: 'SourceCode.HostClientAPI, Version=4.0.0.0, Culture=neutral, PublicKe

    yToken=16a2c5aaaa1b130d' ---> System.Runtime.InteropServices.COMException (0x800

    736B1): The application has failed to start because its side-by-side configurati

    on is incorrect. Please see the application event log or use the command-line sx

    strace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)

    具体使用Microsoft Visual C++ Redistributable Package 的2005,2008,2008 SP1版本,取决于你开发的应用程序所使用Visual Studio的版本。

    Microsoft Visual C++ 2008 SP1 Redistributable Package (x86)

    上述问题发生在我准备在Windows Server 2008 R2 Server Core上部署应用程序所碰到的问题的总结,折腾了将近一天的时间,希望对今后碰到类似问题的同学有帮助,可以节省更多的时间。

  • 相关阅读:
    ADB高级应用
    struts2 结合extjs实现的一个登录实例
    css3中关于伪类的使用
    漫谈并发编程(三):共享受限资源
    awk依照多个分隔符进行切割
    3星|《财经天下周刊》2017年21期:海外购几乎是亚马逊中国的最后一根救命稻草
    3星|《迷失的盛宴:中国保险产业1978-2014》:序言比正文精彩
    3星|《超级运营术》:互联网社区运营老手经验谈
    3星|《百年流水线》:流水线与工业、社会、艺术的交互史
    5星|戴蒙德《为什么有的国家富裕,有的国家贫穷》:为什么有的国家能发展出好制度
  • 原文地址:https://www.cnblogs.com/Qbit/p/2236187.html
Copyright © 2011-2022 走看看