ASP.NET web forms + Spring.NET transition to StateServer problem


I am trying to improve the legacy app written in the ASP.NET with NHibernate 4 and Spring.NET and move it's session state to the StateServer (local ASP>NET State Service) in order to speed up the request processing. I've got errors related to the problem of the serialization:

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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

I went already throught all the objects that are used via container (services, repositories, config objects, etc.) and now the things are getting messy as the IIS is starting to reach Spring.NET classes:

[SerializationException: Typ 'Spring.Objects.Factory.Support.WebObjectFactory' w zestawie 'Spring.Web, Version=, Culture=neutral, PublicKeyToken=null' nie jest oznaczony jako możliwy do serializacji.] System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +12672447
System.Runtime.Serialization.<>c__DisplayClass9_0.b__0(MemberHolder _) +42 System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) +73
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +186
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +166 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +187
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +581
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +470 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +137 System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1619

[HttpException (0x80004005): Nie można serializować stanu sesji. W trybie 'StateServer' i 'SQLServer' aplikacja ASP.NET będzie serializować obiekty stanu sesji i dlatego obiekty niemożliwe do serializacji lub obiekty MarshalByRef nie są dozwolone. To samo ograniczenie ma zastosowanie, jeśli podobna serializacja jest wykonywana przez magazyn niestandardowych stanów sesji w trybie 'Custom'.]
System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1708
System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +35
System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +641
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +241
System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length, Boolean compressionEnabled) +62
System.Web.SessionState.OutOfProcSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +110
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +686
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +201 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +132 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73

In reagards to that I have couple of questions:

  1. Why IIS is touching these objects ? The session state is used in the project to store some classes that are not using these references.
  2. Does anyone worked with Spring.NET with session state other than InProc and could share one's experience ?
  3. How to avoid changes in the Spring.NET library ?
  4. How to write unit test that could detect such objects?

Rewriting the whole app is not an option. Removal of the Spring.NET could be an option.

System version info: .NET Framework:4.0.30319; ASP.NET:4.8.4210.0

Edit 1

Answer to the question 1 is quite simple: you can specify the scope of the objects and some of them were using scope="session" which means that the Spring.Net was creating some proxies in order to store them in the session state. They have to be serializable hence when using some external library then there was an error related to that. And also question number 3 can be answered the same way.
asked on Stack Overflow Oct 7, 2020 by kliszaq • edited Oct 8, 2020 by kliszaq

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0