I am using StructureMap to store a session object:
config.For<SessionContext>().LifecycleIs(new HttpSessionLifecycle());
And everything works okay, so I can easy retrieve the session object with DI.
But now I need to switch my session from in-process to the database, but I receive 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. —>
System.Runtime.Serialization.SerializationException: Type
‘StructureMap.Pipeline.MainObjectCache’ in Assembly ‘StructureMap,
Version=2.6.2.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223’ is
not marked as serializable.
How can I solve this problem?
The problem was in StructureMap. I’ve added the [Serializable] attribute to the
MainObjectCacheclass and some others and tested it out. It works now. The fix can be found in this pull request.I hope @Joshua Flanagan will merge these changes into the master branch soon and the problem will be finally solved.
Edit: