A class must be marked with the Serializable bit to be Serialized. An exception is thrown during serialization if the bit is not set of any class involved in the graph being serialized.
In C#, this bit is set with a reserved custom attribute
[Serializable] public class MyClass {}
Classes with this addribute have all fields (even private ones) serialized.