2

I heavily use a DataContractSerializer to store projects within my application. When I want to open a previously saved file, how can I ensure the integrity and/or structure of the file before I start deserializing it? Is there something like a version id which one can provide? Or maybe a annotation property? Thanks!

  • If it doesn't deserialise then its in the wrong format! You can validate its schema against an XSD document. – Lloyd Jan 28 '12 at 12:52
  • Is the DCS able to generate a schema? – user1175165 Jan 28 '12 at 12:53
  • How to create an XML Schema in VS 2010... http://msdn.microsoft.com/en-us/library/ms255829.aspx http://msdn.microsoft.com/en-us/library/ms162371.aspx – Lloyd Jan 28 '12 at 12:58
  • Here is another method using the SVCUtil in VS... http://stackoverflow.com/questions/2604032/is-there-a-way-to-export-an-xsd-schema-from-a-datacontract – Lloyd Jan 28 '12 at 13:14
  • In most cases DCS will be pretty friendly when versioning. Do you have a specific scenario you are trying to guard against? – Marc Gravell Jan 28 '12 at 13:15
  • It's a model based development environment I'm working on. Users are able to extend the application with plugins (using MEF), but little differences in the plugin definitions cause errors. When you saved your model and than update the plugin which has one more datafield, the deserialization gives a very unhandy error message... I just want to check if the model is loadable and if not, display an appropriate error message – user1175165 Jan 28 '12 at 13:19

0 Answers0