我已閱讀文章ASP.NET application pool shutdown problem和IIS 7.5: problem with Application pool但他們沒有回答我的問題。爲什麼我的IIS7應用程序池在從ASP.NET頁面調用的DLL中的異常之後關閉?
我有一個C#ASP.NET頁面,在代碼實現中,通過BIN目錄提供的DLL實例化一個類,然後在這個實例上調用一個方法。由於DataRow
對象中不存在列,因此DLL中的方法會拋出System.ArgumentException
。事件日誌顯示以下錯誤:
Source: ASP.NET 2.0.50727.0
Application ID: /LM/W3SVC/1/ROOT/...
Process ID: 9476
Exception: System.ArgumentException
Message: Column 'someColumn' does not belong to table.
StrackTrace:
在ASP.NET頁面調用代碼封裝在一個通用的try-catch
塊的方法調用。當我請求頁面時,這會崩潰我的IIS實例的相應應用程序池,並且我的網站不再可用(錯誤503)。我手動必須重新啓動應用程序池,並再次工作。
更新 作爲要求try catch
塊從背後的ASP.NET代碼:
try
{
SomeExternalClass someExternalClass = new SomeExternalClass();
someExternalClass.SomeMethod(someId);
}
catch(Exception ex)
{
// "smp" is an instance of "StatusMessagePanel", a control we use on all pages
// to show error information, basically a div container with an icon.
smp.ShowError(ex.Message);
}
現在我的問題是,爲什麼一個相對「簡單」的例外,如試圖訪問時System.ArgumentException
被拋出不存在DataRow
列,崩潰整個網站? ASP.NET頁面的通用塊try-catch
也沒有幫助,這也不應該是完全使整個網站不可用的原因,或者這是一個錯誤的假設?我從來沒有想過,這基本上可以把(II)服務器關閉。
預期人們告訴我,我應該檢查列存在之前,我訪問他們:我知道這一點,遺留代碼現在已經改變,但這不是我的問題,如上所述,我想知道爲什麼後果如此激烈。
更新2
問題的方法被調用的DLL裏面會啓動裹在try-catch
阻塞線程:
[...]
try
{
ThreadStart starter =() => CreateReport(...)
Thread thread = new Thread(starter);
thread.Start();
if(!thread.Join(TimeSpan.FromMinutes(15)))
{
// Log some timeout warning
}
else
{
// Log information about successful report generation
}
}
catch(Exception ex)
{
// Log error information
}
在catch塊會發生什麼?如果拋出異常,你可能會遇到麻煩。你可以發佈try catch代碼嗎? – levelnis
catch塊調用一個方法,使客戶端(瀏覽器)可見錯誤消息,我會更新我的問題。 – Gorgsenegger
只是爲了幽默我 - 如果你完全刪除try-catch塊並且只是調用方法,應用程序池是否仍然崩潰? – levelnis