巧手一指,快速解掉同事遇到的鬼問題,自己都覺得神奇。

ASP.NET Web Site 專案在部署用 wdproj 編譯 DLL 部署後壞掉,爆炸點出現在多處,幾個讀 Registry、開 SQL 連線的網頁噴出以下訊息:

Failed to load config XML: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ApplicationException: Failed to load config XML: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

看到這個錯訊息腦中立刻浮現 - Trust Level! 與之前將部落格網站搬上 ASP.NET Hosting 空間信任層級不足時出現的錯誤訊息相同。(漫漫搬家路~~~)

但本次更新沒更動 web.config,檢查 IIS 管理員設定,站台的 Trust Level 是 Full 沒錯。於是我將箭頭指向本次部署更新的 App_Code.dll ,福至心靈打開檔案屬性檢查,果然...

App_Code.dll 被註記為不可信任,會引發古怪問題,過去有交手經驗:

之前遇過網路下載 ZIP 解出 DLL 檔無法編譯,本案例則是從網路芳鄰解壓 ZIP 檔取出 DLL,解出的 DLL 也會被加上註記,但 ASP.NET 因此出錯的案例還是第一次遇到。另外,實測解鎖後建議 IISRESET 確保修改生效,而 DLL 解鎖後再次從網路分享解壓覆寫不會恢復鎖定狀態。

剛好知道 Trust Level、有組件被封鎖的經驗,才能第一時間找對方向解開問題。像我這種老骨頭,吃鹽吃得夠多還是有點優勢囉~

A case of assebmly downloaded from network can cause ASP.NET throw request for the permission failure exceptions.


Comments

# by Circle

棘手的問題常常都在這裡看到線索 感謝

Post a comment