2015-12-03 28 views
0

我正在IIS下運行帶有狀態服務器的ASP.net網站。一個對象無法序列化,但我不知道哪一個。有沒有辦法讓IIS或Visual Studio告訴我哪個對象無法序列化?哪一個對象不能被序列化?具有狀態服務器的IIS會話狀態

謝謝。

********** 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: 
+1

你能嘗試捕獲SerializationException並將其粘貼到此處嗎?看看[這個答案](http://stackoverflow.com/questions/5889240/unable-to-serialize-the-session-state) –

回答

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; 
} 
+0

這工作,謝謝。很清楚地告訴我這個對象是不可序列化的。 – bruestle2

+0

我很高興聽到這個消息。 :)現在是時候找到誰把它放在那裏:) –