Visual Studio 64位應用程式編譯

2021-09-10 07:53:11 字數 3691 閱讀 6480

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

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

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上部署應用程式所碰到的問題的總結,折騰了將近一天的時間,希望對今後碰到類似問題的同學有幫助,可以節省更多的時間。

再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智慧的隊伍中來!

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

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

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上部署應用程式所碰到的問題的總結,折騰了將近一天的時間,希望對今後碰到類似問題的同學有幫助,可以節省更多的時間。

用Visual Studio 編譯64位程式

由於硬體的公升級,目前伺服器處在乙個從x86到x64的過渡時期。如果用vs2008在x64位機上編譯程式,有時候會遇到 試圖載入格式不正確的程式 的錯誤資訊。如下圖所示 幾乎可以肯定是遇到了 x86和 x64位 dll混編的錯誤。所謂 x86和 x64位 dll混編 是指 32位程式集與 64位程式...

用Visual Studio 編譯64位程式

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!由於硬體的公升級,目前伺服器處在乙個從x86到x64的過渡時期。如果用vs2008在x64位機上編譯程式,有時候會遇到 試圖載入格式不正確的程式 的錯誤資訊。如下圖所示 幾乎可以肯定是遇到了x86和x64位dll混編的錯誤。所謂 x86和x64位d...

用Visual Studio 編譯64位程式

由於硬體的公升級,目前伺服器處在乙個從x86到x64的過渡時期。如果用vs2008在x64位機上編譯程式,有時候會遇到 試圖載入格式不正確的程式 的錯誤資訊。如下圖所示 幾乎可以肯定是遇到了x86和x64位dll混編的錯誤。所謂 x86和x64位dll混編 是指32位程式集與64位程式集混合編譯,造...