Tag Archives: serializate object

Serialize an object to string and from string back to object

Serialization enables us to store or transmit data structures or objects. This can be done by converting the data to a textual representation when storing or transmitting them which also allows us to recreate the original object using the stored information.

Lets create a dummy class called Person, that will hold some basic information.

Keep in mind that your class needs to have a parameterless constructor in order to be serialized or else you will get an InvalidOperationException exception (cannot be serialized because it does not have a parameterless constructor) if you try to serialize a class without one. Luckily you can just set it to private or internal so it won’t be accessible from other classes.

Now it is time to serialize our Person object.