Does the .NET runtime maintain object references when serializing to SQL Session State/InProc Session State; during serialization/deserialization? In the following example, I'd expect the references to point to the same object. Can someone explain why this isn't the case.
E.g.:
var list = new List<Foo> { new Foo { Name = "foo" }, new Foo { Name = "bar" } };
var bar = list.Single(x => x.Name == "bar" );
Session["list"] = list;
Session["bar"] = bar;
var listDeserialized = (List<Foo>)Session["list"];
var barDeserialized = (Foo)Session["bar"];
Assert.IsTrue(Object.ReferenceEquals(listDeserialized[1], bar)); // false
/* class definition */
[Serializable]
public class Foo {
public string Name { get; set; }
}
Note: Assume that the list
and bar
objects have already been serialized/persisted to SQL.