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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值