I’m currently convering my ASP.NET v2 application to serialize/deserialize it’s objects because I want to shift from inproc session state to stateserver. This is because my host, webhost4life, has a nasty tendency to recycle the worker process frequently thus causing session timeouts. Anyway… the question…
I’m trying to not serialize things I don’t need to, i.e. variables that are re-initialised each page, don’t need to be serialised. Here’s one of them:
Private RollbackQueue As New Queue(Of DataServer.Rollback)
On deserialisation, will RollbackQueue be a) nothing or b) an empty queue? My guess is that when .NET deserialises, it creates the parent object as normal and then fills in the fields one by one. Therefore, the NEW bit will fire.
But that is a guess.
Thanks, Rob.
It will be nothing. The CLR serialization logic will create the object uninitialized by way of FormatterServices.GetSafeUnitializedObject without running any construction logic. If you need to ensure the field has a value I would recommend moving such initialization into an
Initialize()method that is called both from your constructor and from a method marked with the OnDeserialized attribute.