Serialization in Sitecore

0

I have a custom module in Sitecore which works fine if app pool session state is set to In process. When I change it to SQL Server I get error message saying that it is Unable to serialize the session state. All my classes I am using are serializable. My code is triggered by custom ribbon button and this error is thrown when I click on it. It is supposed to display dialog form but it shows error message instead. I thought it has sth to do with Sitecore DialogForm class which my class inherits, but it turned out that this is not the case.

When I debug the code error is thrown once Run(TranslateArgs args) method has finished executing - it is called from public override void Execute(CommandContext context) and is supposed to display dialog by calling SheerResponse.ShowModalDialog(str4.ToString(), true);

I also thought that it was because I used ClientPipelineArgs in Run method, but after creating custom class (and making it serializable) that inherits ClientPipelineArgs error didn't go away.

Any ideas what might be causing it?

Stack Trace:

[SerializationException: Type 'Sitecore.Data.Database' in Assembly 'Sitecore.Kernel, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]
   System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +14210117
   System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +408
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +420
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +532
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +969
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +633
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +322
   System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1487

[HttpException (0x80004005): 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.]
   System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +2252727
   System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +49
   System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +729
   System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +336
   System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length, Boolean compressionEnabled) +99
   System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +3538900
   System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +1021
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165
c#
serialization
sitecore
asked on Stack Overflow May 31, 2016 by James • edited Jan 28, 2019 by Sitecore Sam

2 Answers

0

Well the stack trace tells us, that some code is trying to put a Sitecore.Data.Database onto SessionState, and that won't work. It has no public constructor, but that is the very least of the problems. It can happen if trying to put an instantiated Item onto SessionState as well.

The stack trace appears to be incomplete. It should show you, which line of code in your Run method, is the root source of the exception.

What isn't clear to me; which exact version of Sitecore are you on?

answered on Stack Overflow Jun 2, 2016 by Mark Cassidy
-1

Currently out-of-process session state mode is experimental feature in Sitecore. InProc is the best option for the Client. Find more details here. If you still think that out-of-process is the right way to go, make sure you set it in accordance with this article.

[Update] Out-of-process session states are not supported on Content Management instance anymore. Link.

answered on Stack Overflow Jun 1, 2016 by Vladimir • edited May 29, 2018 by Vladimir

User contributions licensed under CC BY-SA 3.0