在工作機 IIS 測試 ASP.NET 網站,得到「An attempt was made to load a program with an incorrect format /試圖載入格式錯誤的程式」,這是經典問題,一看訊息就知是 32/64 位元版本不對,好發於在 x64 Windows 使用 32 位元 Oracle Client 的情境。基本上只需在 IIS AppPool 進階設定啟用 32 位元模式即藥到病除。這回狀況不同,啟用 32 位元後網站徹底掛點,顯示 HTTP 503,事件檢視器可觀察到 AppPool 因連續出錯被關閉,錯誤訊息指出與無法載入 C:\Windows\System32\inetsrv\appnetcore.dll 有關。
![](http://www.darkthread.net/Photos/4357-49cb-o.gif)
爬文得知是 Win8.1 升級 Win10 的後遺症,asnetcore.dll 區分 x86 跟 x64 版,分別位於 "%windir%\system32\inetsrv\aspnetcore.dll" 及 "%windir%\syswow64\inetsrv\aspnetcore.dll",但在升級 Win10 過程 syswow64 下的 aspnetcore.dll 被意外移除,據說在 Windows 10 Insider Build 15002 已修復,這種小問題靠更新 OS 修復感覺很蠢,決定另尋他法。
找了幾台 Windows 10 也沒看到 \syswow64\inetsrv\aspnetcore.dll,自行補檔的計劃告吹。
查詢 IIS 模組設定還真的有個 AspNetCoreModule,試過將其從站台移除無效,下一步應該試試從根網站或 IIS 完全移除模組,但有點治跛腳要截肢的 fu,我也不愛。
![](http://www.darkthread.net/Photos/4358-98ae-o.gif)
討論串提到修復「Microsoft .NET Core 1.0.0 – VS 2015 Tooling Preview 2」可以解決問題,值得一試:
![](http://www.darkthread.net/Photos/4359-7729-o.gif)
很不幸地,在我的電腦上,套件無法修復或解除安裝,移除項目後重裝也告無效。
![](http://www.darkthread.net/Photos/4360-be06-o.gif)
最後,我採用 MVP Rick Strahl 建議的解法,修改 C:\Windows\System32\inetsrv\config\applicationHost.config,找到 <add name="AspNetCoreModule" image="%SystemRoot%\system32\inetsrv\aspnetcore.dll" preCondition="bitness64" /> 加上 preCondition="bitness64",指定只有 64 位元模式才載入 aspnetcore.dll,IISRESET 再試一次,IIS 網站總算正常了。