Question

As you know, in ASP.NET, you can store session data in one of following three modes:

  • InProc
  • Session State
  • SQL Server

For InProc mode, you can store any kind of data objects even it's not serializable. However, in Session State and SQL Server modes, you can only store serialized data.

In my project, I have a ready made portal which use "InProc" mode to store its session. I need to use Session State instead due to some scalability and failure handling issues.

The problem that this portal is internally storing unserialized objects in the session context (i.e The stored objects doesn't implement ISerializable interface). I have no access to their code. Is there any work around so that I can be able to store the session objects in State Server without changing their code. I still have access to their web.config file if this would help in any kind.

Was it helpful?

Solution

AFAIK, the simple answer is no. If you don't mind changing your code, you could inject a wrapper object between the actual object and yours, and make your wrapper deal with serializing the wrapped object (essentially as a serialization surrogate) - but by then it would almost be easier to simply re-write the code...

What sort of objects are they? Typically, objects for session-state would be simple data classes, so there shouldn't be too much issue serializing them?

OTHER TIPS

Serialisation creates a representation of the object that can be stored and read to re-create the state of the object.

If an object only contains value types then you may not need to implement ISerializable, but only need the [Serializable] attribute.

To make this response more helpful or direct to the question at hand:

You cannot serialise an object that hasn't been delcared in some way as serializable. Any other generic way of re-creating an object might result in the object not having the same state as it had before it was 'serialized'.

As mentioned by Marc, you could do it by creating your own serializable 'wrapper', but you would need to be very familier with the object in question, and the object would need to have methods that would allow it to be re-created in such a way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top