bruestle2
bruestle2

Reputation: 737

Which object can't be serialized? IIS Session State with State Server

I am running an ASP.net website under IIS with a state server. An object is failing to serialize, but I do not know which one. Is there a way for IIS or Visual Studio to tell me which object is failing to serialize?

Thank you.

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

Upvotes: 0

Views: 800

Answers (1)

Oguz Ozgul
Oguz Ozgul

Reputation: 7187

The exception thrown in your case is of type System.Web.HttpException

The InnerException is of type HttpException

Check the inner exception of the inner exception. It will contain the actual serialization exception according to the Reference Source of AltSerialization.WriteValueToStream

The source code of it's try/catch block for serializing non-value and non-well-known types is as follows. You can see the HttpException being built with the more detailed serialization exception as the inner exception. It will give you the actual type that is non-serializable:

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

Upvotes: 1

Related Questions