I have a business class which I need to serialize to xml. It has a BitArray property.
I have decorated it with [XmlAttribute] but the serialization is failing with
To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.Boolean) at all levels of their inheritance hierarchy. System.Collections.BitArray does not implement Add(System.Boolean).
I am not sure whether its possible to serialize to xml?
If not what would be an efficient means of serializing the BitArray
Thanks for looking
You cannot directly serialize a BitArray to XML. The reason is that in order to de-serialize it you’d need an Add method which BitArray doesn’t supply.
You can, however, copy it to an array that can be serialized:
Going the other way involves deserializing the array and calling the BitArray constructor:
If you do this, you’ll want your BitArray size to be a multiple of the word size (i.e. if you use an array of int, then your BitArray size should be a multiple of 32).