0

I have an existing .NET web service that serializes its session state to SQL Server. I want to move some of the classes that make up the session state into a new assembly, but I am aware that this will break deserialization of existing session states. The solution seems to be to implement a custom SerializationBinder and override BindToType (as per Maintain .NET Serialized data compatability when moving classes), but this seems to rely on being able to access the actual BinaryFormatter that the framework uses to deserialize the session state, and I can't work out how to do that, or whether it is even possible. Or is there a better solution?

Community
  • 1
  • 1
matthewk
  • 1,841
  • 17
  • 31
  • Just to state the obvious, but; isn't it easier to deserialize and re-serialize the stored states with the new classes prior to the web app update? – Stefan Mar 22 '17 at 11:55
  • @Stefan I'm not sure I understand what you mean by that; could you elaborate? – matthewk Mar 22 '17 at 12:02
  • I think he means to keep the old session state with objects as they are now, build the changes that will generate the new object graph, and have a crossover time where you have both session states potentially existing in a single user's session. – Eric Lizotte Mar 22 '17 at 12:14
  • No sorry, I think it's due to my lack of experience with actual serialization of the session state. My thought where as follows: for each user; 1) deserialize your stored session state into the appropriate classes. 2) copy these to the new classes (perhaps use an automapper). 3) Serialize new object and store it into the database. – Stefan Mar 22 '17 at 12:19
  • All this of course assuming that you have a relatively small pool of states stored in your database and have sufficient down-time to do this. – Stefan Mar 22 '17 at 12:22
  • @Stefan, perhaps I should have said this in the question, but I don't want any downtime. With downtime it would be a simple matter of just clearing out the old sessions; then there wouldn't be any deserialization issue! – matthewk Mar 22 '17 at 12:35
  • @matthewk: oops, my bad, I thought you where storing them to preserve your sessions during downtime XD – Stefan Mar 22 '17 at 12:39

0 Answers0