System.BadImageFormatException

问题解决!!! 无法启动服务.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)更新包,还会出现类似的错误:

 
 
 
http://www.cnblogs.com/Qbit/archive/2011/11/04/2236187.html

posted on 2014-03-31 14:53  架构师师  阅读(377)  评论(0编辑  收藏  举报

导航