【发布时间】:2011-11-18 08:18:38
【问题描述】:
在最近的压力和容量测试中,我们意识到 30 分钟后,所有使用都与网站断开连接。在事件记录之后,我们注意到应用程序池崩溃了。做一些谷歌调查,显然在大多数情况下这是由于未处理的异常。
所以当应用程序崩溃时,会显示以下异常详细信息:
An unhandled exception occurred and the process was terminated.
Application ID: DefaultDomain
Process ID: 7852
Exception: System.Runtime.Serialization.SerializationException
Message: Type 'FuseFarm.FrameworkException' in Assembly 'FuseFarm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
StackTrace: at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeObject(Object obj, MemoryStream stm)
at System.AppDomain.Serialize(Object o)
at System.AppDomain.MarshalObject(Object o)
我不知道它为什么要序列化 FrameworkException,而且我在代码中也看不到执行此操作的位置。但我确实看到了代码的几个部分,其中
new FrameworkException(exData, "ContractComposition.SubmitContract");
正在被调用,但未被处理。检查 global.asax.cs 后,出现以下情况:
protected void Application_Error(object sender, EventArgs e)
{
ILog log = LogManager.GetLogger(typeof(Global));
string environmentName = WebConfigurationManager.AppSettings["EnvironmentName"];
if (!String.IsNullOrEmpty(environmentName) && (environmentName == "DEMO" || environmentName == "LIVE"))
{
Exception currentException = Server.GetLastError().GetBaseException();
Session["errorMessage"] = currentException.Message;
Session["errorSource"] = currentException.Source;
Session["errorTrace"] = currentException.StackTrace;
log.Error(currentException.Message, currentException);
if (currentException != null)
{
Session["error"] = currentException.GetType().Name;
switch (currentException.GetType().ToString())
{
case "System.ApplicationException":
case "FuseFarm.FrameworkException":
break;
default:
new FrameworkException(currentException.Message + "\n" + currentException.StackTrace, currentException.Source, currentException);
break;
}
}
Server.Transfer("~/error.aspx");
}
}
在 Application_Error 中抛出一个新异常...这似乎不对?如果此时抛出此错误,谁来处理这个错误?
【问题讨论】:
-
好的,我可以看到它不会真正引发新的 frameworkException,因为它会在“FuseFarm.FrameworkException”的情况下中断......但仍然不确定如何解决这个问题。
-
异常在需要跨越 AppDomain 边界时被序列化。运行时正在尝试为您序列化它。因此,所有异常都必须属性实现
ISerializable和序列化构造函数。 -
为什么在检查之前就已经使用了对象的成员: if (currentException != null) ?还是?
标签: c# asp.net exception-handling try-catch