iis 状态服务器,哪个对象不能序列化?状态服务器的IIS会话状态

在运行ASP.NET网站并使用状态服务器时遇到一个对象无法序列化的错误。通过查看异常信息,发现异常类型为System.Web.HttpException,内嵌异常是HttpException,提示无法序列化会话状态。解决方案是捕获SerializationException,它会详细指出哪个对象是非序列化的。通过这种方法,可以明确问题的具体对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

Talk1:

Can you try to catch the SerializationException and paste it here? Check out this answer

Solutions1

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;

}

Talk1:

This worked, thank you. Quite clearly tells me what the object is that was not serializable.

Talk2:

I'm glad to hear that. :) Now it's time to find who put it there :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值