I’m trying to serialize an object cache to disk so it can be loaded the next time the program is loaded.
One of the features of the class being saved is it contains references to other objects.
For example:
I have a list of an image class that stores remote url, local filepath, if it’s been downloaded etc…. I then bind visibility to downloaded and the source to the local filepath.
Other Objects have a reference to this image so when the image is downloaded it’s updated once and all the bindings update across all items that are pointing at it.
As a quick fix I implemented a binary formatter and all is working correctly. All my lists are serialized to disk and when I reload them all the references remain (I.E 1 image object is created and everything that uses it has a reference as opposed to deserialisation creating a new instance of Image everytime it appears)
My question is what kind of Serialier I should be using to store to disk whilst not breaking my references? I’ve read that BinaryFormatter is a BAD choice for serializing to disk and expecting it to work across different releases. Although I’ve had no issues with it so far I don’t want to run into problems a year down the road and force all my users so re-aquire all their cached metadata.
I’m not 100% sure how all the different serializers work but I presume I may need to write some kind of convertor if I were to use XML. If it helps, all of my image objects have a GUID assigned to them so I have something unique about every object.
UPDATE: I’ve just found the following question which looks similar Maintain object references through Serialize/Deserialize
Can anyone tell me if Datacontractserializer is a good choice for long term serialization storage across different versions of an applciation Vs the downsides of binaryformatter?
No need for any converters and stuff, just check this out:
http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization