2

【笨問題】Visual Studio IIS Express 32/64 位元模式設定

 1 year ago
source link: https://blog.darkthread.net/blog/vs-iisexpress-bitness/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【笨問題】Visual Studio IIS Express 32/64 位元模式設定-黑暗執行緒

用 VS2022 偵錯一個 ASP.NET MVC 舊專案,F5 偵錯時噴出經典錯誤:System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B),明顯是 Unmanaged ODP.NET 32/64 位元不符造成。專案過去用 VS2017/VS2019 維護沒出過問題,換成 VS2022 就爆炸,我很快想到應與 VS2022 改為 64 位元有關。情急之下,回頭用 VS2019 修改偵錯,先度過緊要關頭再說。

事後分析,問題出在專案參照了 32 位元的 ODP.NET DLL,VS2022 改用 64 位元,IIS Express 也變成 64 位元,ASP.NET 跑 64 位元卻載入 32 位元 DLL,註定要出 BadImageFormatException。但升級之後無法維護舊專案有點扯,Visual Studio 理應要提供 IIS Express 跑 32 位元的選項。其實選項就在專案屬性頁還蠻明顯的,且早在 Visual Studio 2017 時代就有,只是我從沒注意過:

Fig1_637939207130822447.png

Bitness 預設選項是 Default,在 VS2017/2019 是 x86,VS2022 起變成 x64,類似上回 VS2022 Solution Explorer 無法使用關鍵字尋找屬性、方法,都是預設值改變惹出的問題。

總之,換用 VS2022 偵錯 ASP.NET 若遇到 32/64 位元版本問題,莫急莫慌莫害怕,改一下設定即可。

and has 0 comments

Comments

Be the first to post a comment

Post a comment

Comment
Name Captcha 45 - 36 =

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK