Error when deserializing an object with broken rules using DataContractSerializer

Error when deserializing an object with broken rules using DataContractSerializer

Old forum URL: forums.lhotka.net/forums/t/3270.aspx


pbevis posted on Thursday, July 26, 2007

I'm writing a Windows App that needs to save the state of an BO to a file in the event that the app crashes so the user can recover their work next time they run the app.  I use the DataContractSerializer to serialise the BO to xml and then write it to a file.  However, if the BO was invalid at the time, i.e. there were some broken rules in the ValidationRules collection and I then try to deserialise that object I get an exception stating that I am unable to insert into the readonly ValidationRules collection.

Is this a known problem? Is there a workaround?

Thanks in advance

Paul

RockfordLhotka replied on Thursday, July 26, 2007

The DataContractSerializer can't handle the complexity of all .NET types. You should use the NetDataContractSerializer instead, it is more capable.

pbevis replied on Thursday, July 26, 2007

Wicked! Thanks Rocky

Copyright (c) Marimer LLC