我碰到的这几次,它的通常缺少的依赖,并总是超级沮丧。
在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