0

Is there a way to rename a typed DataSet but still allow it to deserialize data serialized using the previous name/schema settings?

Example:

Having the original serialized DataSet stored in ASP.NET session state in a database named DSAdmin, after renaming it to AdminDataSet and logging in again an exception will be thrown since it can not deserialize to the new type from the old type stored in the session DB:

[SerializationException: Unable to load type DAL.DataSets.DSAdmin required for deserialization.]
   System.Runtime.Serialization.ObjectManager.DoFixups() +14219464
   System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +244
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +447
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage) +28
   System.Web.Util.AltSerialization.ReadValueFromStream(BinaryReader reader) +1224
   System.Web.SessionState.SessionStateItemCollection.ReadValueFromStreamWithAssert() +108
   System.Web.SessionState.SessionStateItemCollection.DeserializeItem(String name, Boolean check) +338
   System.Web.SessionState.SessionStateItemCollection.get_Item(String name) +27
   MasterPage.OnInit(EventArgs e) in x:\iis\wwwroot\Admin\MasterPage.master.cs:60
   System.Web.UI.Control.InitRecursive(Control namingContainer) +186
   System.Web.UI.Control.InitRecursive(Control namingContainer) +291
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2098

Update

SchemaSerializationMode property of the dataset being set to IncludeSchema.

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
  • Not sure, but possibly it could help to make the new type derive from the old type. Yes, it isn't a straight rename, but should help in maintaining backwards compatibility with the old name. – Marjan Venema May 19 '15 at 16:08
  • possible duplicate of [Is it possible to recover an object serialized via "BinaryFormatter" after changing class names?](http://stackoverflow.com/questions/25701481/is-it-possible-to-recover-an-object-serialized-via-binaryformatter-after-chang) That question answers how to deal with a renamed type. Not sure about your changed "schema settings" however, so if that answer is incomplete, can you give an example of how your schema changed? – dbc May 19 '15 at 18:57
  • See also here: http://stackoverflow.com/questions/19490113/c-sharp-binaryformatter-deserialize-with-the-object-in-another-namespace – dbc May 19 '15 at 18:59
  • @dbc: Thanks for the replies. I ended up clearing the cache. I will have a look at this later. – Răzvan Flavius Panda Jun 23 '15 at 22:01

0 Answers0