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上部署应用程序所碰到的问题的总结,折腾了将近一天的时间,希望对今后碰到类似问题的同学有帮助,可以节省更多的时间。

  • 相关阅读:
    Windows server 2016 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同。”
    Windows Server 2016 辅助域控制器搭建
    Windows Server 2016 主域控制器搭建
    Net Framework 4.7.2 覆盖 Net Framework 4.5 解决办法
    SQL SERVER 2012更改默认的端口号为1772
    Windows下彻底卸载删除SQL Serever2012
    在Windows Server2016中安装SQL Server2016
    SQL Server 创建索引
    C#控制台或应用程序中两个多个Main()方法的设置
    Icon cache rebuilding with Delphi(Delphi 清除Windows 图标缓存源代码)
  • 原文地址:https://www.cnblogs.com/Qbit/p/2236187.html
Copyright © 2011-2022 走看看