I am in the sitaution where I need to use an external session state server, which requires all my sessions to be serialized. I have been trying to make all the classes I store in sessions serializable, by using the [Serializeable()] attribute.
However, I keep getting the following error:
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.
More interesting is however the stack trace:
[SerializationException: Type 'ASP.useroverview_aspx' in Assembly 'App_Web_pwonykbc, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +9452985
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +247 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +160 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +218 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +388 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +444 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +133 System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1708
The Type ASP.useroverview_aspx is as far as I know an ASPX page. The page I load is Useroverview.aspx. However, I don't try to store this page in a session. So this error makes me wonder quite a lot.
I tried to do the following in the code-behind:
[Serializable()]
public partial class UserOverview : Page
{
priv开发者_开发问答ate static readonly int TimerInterval = HttpContext.Current.IsDebuggingEnabled ? 2000 : 750;
// ...
}
This did not help at all!
So I wonder if one could serialize an ASPX page? This don't know if this would make sense. I doubt it!
Thanks...
I found the answer.. And you guys were right: One of my objects had a reference to the page.
I had an object Player, which had a list of events. One of these events had the current page as a target, which let to the problem.
I gave the event the following non serializable attribute:
[field: NonSerialized]
Then everything worked fine. And they all lived happily ever after!
加载中,请稍侯......
精彩评论