我碰到的這幾次,它的通常缺少的依賴,並總是超級沮喪。
在Fluent初始化期間拋出異常的事實有時會使異常有點誤導,因爲它根本不是FNH異常。 ReflectionTypeLoadException
也將異常保存爲LoaderExceptions
屬性中的數組,這一事實也使得挖掘更多的工作。
注意確保您的個別項目中的引用是一致的。例如,當我讓R#爲我已經在另一個項目中使用Nuget映射的項目添加依賴項時,我遇到了這個問題。第二個項目得到了一個本地很好的參考,但在服務器上是無效的(並且沒有使用Nuget解決),使得在本地重現更加困難。
無論如何,這裏有一個代碼片段可以幫助你追蹤罪魁禍首。本示例來自使用Global.asax的MVC應用程序,但可以輕鬆地適用於其他項目類型。
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (null == ex || ex is ThreadAbortException)
{
// could be due to redirect
return;
}
if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
{
// don't want to log this
return;
}
LogException(ex);
}
private void LogException(Exception exception)
{
if (exception is ReflectionTypeLoadException)
{
foreach (Exception loaderException in ((ReflectionTypeLoadException)exception).LoaderExceptions)
{
LogException(loaderException);
}
if (null != exception.InnerException)
{
LogException(exception);
}
}
else if (null != exception.InnerException)
{
LogException(exception.InnerException);
}
// you might also choose System.Console.WriteLine(...), System.Diagnostics.Trace.WriteLine(...), etc.
System.Diagnostics.Debug.WriteLine(exception.Message);
// or send to your favorite logger...this is log4net
Log.FatalFormat("Unhandled error in the website: {0}", exception);
}
我已經手動添加和移除了Dll的數千倍,並且通過設置本地複製true仍然沒有運氣。 – 2013-05-11 19:16:15