how to convert byte[] to an ArrayList of Hashtables?
Question
Could someone please give me an example on how can I convert a byte[] to an ArrayList of Hashtables with C# ? (the byte[] represents the ArrayList of Hashtables that was previously serialized)
Note: I'm running under Windows Mobile, which does not provide BinaryFormatter.
Solution
Also, my ArrayList is automatically converted by the database API into the byte[]
Frankly, you are going to have to find the actual serialization API used to stand a chance of reconstructing this data. It is probably BinaryFormatter
, which is notoriously non-portable and version-intolerant.
If you need to store data as binary, and use it long-term (database) and between platforms (CF), then you are going to have to use a suitable serializer. For example, protobuf-net would work in principal (although it won't like untyped ArrayList
, preferring typed List<T>
etc).
If the data is currently stored as BinaryFormatter
, then your best bet would be to extract it using your current system and re-package it (perhaps in a different column or table) in a more suitable serialization format.
OTHER TIPS
When you say "that was previously serialized" do you mean "serialized with BinaryFormatter
"? If so, no - you'd need BinaryFormatter
to deserialize too. If the Compact Framework doesn't support that, you're basically out of luck. I mean, if the serialization format is documented somewhere (I'm not sure whether it is or not) you could write your own BinaryFormatter
- but it would probably be somewhat tricky.
Instead, you should choose a serialization format which is supported everywhere you need to serialize/deserialize.