﻿# ASP.NET 在 x64 系統執行含有 32 位元 COM 元件的注意事項

今天在處理一個很久沒經手的專案，結果在設立執行環境時 ( Win7 x64 + IIS7 ) 卻遇到了無法載入組件的錯誤訊息 ( Could not load file or assembly 'Interop.ActiveDs' or one of its dependencies. An attempt was made to load a program with an incorrect format. ) 其中文錯誤訊息為 "無法載入檔案或組件 ‘'Interop.ActiveDs' 或其相依性的其中之一。 系統找不到指定的檔案。" ，雖然這個問題之前遇到過，不過由於久沒處理過這個案子，忘記了這個案子有用到 32 位元的 COM 元件，因此必須要設定 IIS7 的應用程式集區才能讓網站正常載入 COM 組件並正常執行。

![Could not load file or assembly 'Interop.ActiveDs' or one of its dependencies. An attempt was made to load a program with an incorrect format](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/fd794179b2be25f44f5b-image_384.png "Could not load file or assembly 'Interop.ActiveDs' or one of its dependencies. An attempt was made to load a program with an incorrect format")

修正方式也很容易，只要在執行該網站的應用程式集區 (Application Pool) 的 \[**進階設定**\] 中將 **啟用 32 位元應用程式** 項目設定為 **True** 即可。

![alt](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/bc7eea686b378e81b59b-image_385.png "title")

![alt](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/b979b8668caf9639831b-SNAGHTML2d2a293.png "title")

中文版的參考設定畫面如下：

![alt](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/be6d2811ef2832a1d4a0-image_386.png "title")

**相關連結**

-   Could not load file or assembly 'Name' or one of its dependencies. An attempt was made to load a program with an incorrect format.
-   [\[Resolved\] Could not load file or assembly 'XXXXX' or one of its dependencies. An attempt was made to load a program with an incorrect format.](https://web.archive.org/web/20131002143825/http://weblogs.asp.net/hosamkamel/archive/2009/10/11/resolved-could-not-load-file-or-assembly-xxxxx-or-one-of-its-dependencies-an-attempt-was-made-to-load-a-program-with-an-incorrect-format.aspx)
-   [Could not load file or assembly 'Interop.ActiveDs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.](http://social.msdn.microsoft.com/Forums/en/netfx64bit/thread/5a92a204-81fe-4c6f-bfc3-ef04dc932ed0)
-   [I get a “An attempt was made to load a program with an incorrect format” error on a SQL Server replication project](http://stackoverflow.com/questions/41449/i-get-a-an-attempt-was-made-to-load-a-program-with-an-incorrect-format-error-on)
