I wanted to minimize changes to code in my save-file function by only making changes in the class that will be saved. Instead of making a "save-file" function in the class, I decided to try making it serializable but I receive a runtime error saying "PublicKeyToken=null" not marked as serializable.

Here's the class I want to make serializable:

[Serializable()]
    public class Marker// : ISerializable     
    {
        public Marker()
        {
            commonId++;
            id = commonId;
        }
        public AAShape shape;
        public int nextLinkId;
        public int id;
        static int commonId = 0;

        
        //public void GetObjectData(SerializationInfo info, StreamingContext context)
        //{
        //    if (info == null)
        //        throw new System.ArgumentException("info == null");
        //    info.AddValue("Shape", shape);
        //    info.AddValue("nextLinkId", nextLinkId);
        //    info.AddValue("id", id);
        //    info.AddValue("commonId", commonId);
        //}
    }

also note that AAShape is a different class that I will also make serializable.

You will need to make sure that all types used in the class are serializeable, this means that you will need to make AAShape serializeable now and not later.

This article has been dead for over six months. Start a new discussion instead.