我在IIS下运行一个带有状态服务器的ASP.net网站。一个对象无法序列化,但我不知道哪一个。有没有办法让IIS或Visual Studio告诉我哪个对象无法序列化?
谢谢。
********** 12/3/2015 9:22:23 PM **********
Exception giud: 3fa14c14-cad5-48fa-a23a-7eccc3340093
Inner Exception Type: System.Web.HttpException
Inner Exception: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
Inner Source: System.Web
Inner Stack Trace:
at System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer)
at System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer)
at System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer)
at System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream)
at System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length, Boolean compressionEnabled)
at System.Web.SessionState.OutOfProcSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem)
at System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Exception Type: System.Web.HttpException
Exception: Server Error: 500
Source: HttpError
Stack Trace:
答案 0 :(得分:1)
您的案例中抛出的异常属于System.Web.HttpException
InnerException
的类型为HttpException
检查内部异常的内部异常。它将根据Reference Source of AltSerialization.WriteValueToStream
包含实际的序列化异常用于序列化非值和非众所周知类型的try / catch块的源代码如下。您可以看到使用更详细的序列化异常构建的HttpException作为内部异常。它将为您提供不可序列化的实际类型:
try {
formatter.Serialize(writer.BaseStream, value);
} catch (Exception innerException) {
HttpException outerException = new HttpException(SR.GetString(SR.Cant_serialize_session_state), innerException);
outerException.SetFormatter(new UseLastUnhandledErrorFormatter(outerException));
throw outerException;
}