0

Is it possible to serialize a class inheriting from microsoft.practices.enterpriselibrary.validation.validationresults.

When I create the object of

XmlSerializer xs = new XmlSerializer(typeOf(subclass of ValidationResults));

it gives following exception at runtime.

To be xml serializable types which inherit from ienumerable must have an implementation of add(system.object) at all levels of their inheritance hierarchy. microsoft.practices.enterpriselibrary.validation.validationresults does not implement Add(System.Object) method.

Why do I get this exception? Is there any workaround for this issue. So that I can serialize the ValidationResults?

croxy
  • 4,082
  • 9
  • 28
  • 46
Rafeeqh
  • 1
  • 1
  • 1) Do you need to deserialize it later? 2) What does your subclass of `ValidationResults` look like? If it has properties you want to serialize, `XmlSerializer` will not serialize them. See [How/why does XmlSerializer treat a class differently when it implements IList?](http://stackoverflow.com/questions/31552724) and also [How to serialize an ICollection that also has read/write properties to XML](https://stackoverflow.com/questions/34221481). – dbc Jan 20 '16 at 17:36
  • Thank you for your response. Please see my comments below.1. I may have to de-serialize it later. coming to the second part of your question I have already mentioned that ValidationResults is class provided my Microsoft enterprise library. The complete name space is Microsoft.Practices.Enterpriselibrary.Validation.ValidationResults and don't have freedom to alter this library. Hence I can't just go ahead and implement Add method to satisfy the runtime request of XmlSerialzer. Hence trying to search a work around for this issue. – Rafeeqh Jan 21 '16 at 05:08
  • Can you show a code example of your subclass of [`ValidationResults`](https://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.validation.validationresults.aspx)? What data or properties does the subclass have that need to be serialized? Also, can you make changes to the subclass? – dbc Jan 21 '16 at 16:50

0 Answers0