Hi,
I've inherited a ASP.NET project where the sponsors want to move from InProc to SQLServer for StateStorage. One problem we ran into is that there is a fair amount of use of DataRows as Session variables. As these are not serializable we introduced a workaround by creating a serializable class that contains a DataSet, TableName and Row Index, so when we assign a Row reference to the session variable it packages it in the custom object so it can be serialized.
Now that seems to have worked except for in one area. There is a case where there are three session variables
a serializable object with a dataset property
a datarow that points to a row within one of the dataset's tables
another datarow that points to a row within a different table in the dataset
What seems to be happenning is that the references get messed up between server hits (I'm guessing on deserialization)
I had a watch where I was checking to see if rowa.table.dataset IS rowb.table.dataset. This started out as true but on one of the postbacks it would change to false before any code is executed.
The basic effect is that updating properties of one of the Row objects after that point do not set the properties in the Parent dataset. So it seems that the datasets that the rows reference are now copies and not referring to the same dataset object.
Browsing around the net I found a small tidbit
"In real life, objects are often serialized together, with some objects in the serialization stream depending on other objects. This presents a problem, as during deserialization there is no guarantee on the order that specific objects are reconstituted."
It didn't explain what to do in any detail. Note that when I switch back to InProc everything works fine.
If anybody could help me out with this, I'd appreciate it.
Cheers,
Chris

Serialization and Object Reference Problems
sugavaru
If memory serves they write out the values to XML and then populate SerializationInfo.
It is possible that there is something going on there.
I suggest that you find another way to id the rows in question (by name, etc) and store that in the session.
Daisy34001
Iam using UIP session management techniques.We are storing an entire dataset into session to be used in other pages.At Random times this type of error is encountered.
System.Exception: Original Exception Type: System.InvalidOperationException Message: Handle is not initialized. StackTrace: at System.WeakReference.get_Target()
at System.Data.Index.get_RowFilter()
at System.Data.Index.Equal(Int32[] indexDesc, DataViewRowState recordStates, IFilter rowFilter)
at System.Data.DataTable.GetIndex(Int32[] indexDesc, DataViewRowState recordStates, IFilter rowFilter)
at System.Data.DataKey.GetSortIndex(DataViewRowState recordStates)
at System.Data.DataKey.GetSortIndex()
at System.Data.DataRow.GetChildRows(DataRelation relation, DataRowVersion version)
at System.Data.XmlDataTreeWriter.XmlDataRowWriter(DataRow row, String encodedTableName)
at System.Data.XmlDataTreeWriter.SaveDiffgramData(XmlWriter xw, Hashtable rowsOrder)
at System.Data.NewDiffgramGen.Save(XmlWriter xmlw, DataTable table)
at System.Data.DataSet.WriteXml(XmlWriter writer, XmlWriteMode mode)
at System.Data.DataSet.System.Runtime.Serialization.ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at System.Web.UI.LosFormatter.SerializeValue(TextWriter output, Object value)
at System.Web.UI.LosFormatter.SerializeValue(TextWriter output, Object value)
at System.Web.UI.LosFormatter.SerializeInternal(TextWriter output, Object value)
at System.Web.UI.LosFormatter.Serialize(TextWriter output, Object value)
at Microsoft.ApplicationBlocks.UIProcess.WebStatePersistence.SerializeWebStates()
at Microsoft.ApplicationBlocks.UIProcess.StateManagementPage.StateHandler_PreRender(Object sender, EventArgs e)
at System.Web.UI.Control.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain()
Why is this happening and Is there a solution for this