V
V
Vitaly Pukhov2015-05-07 15:43:26
Programming
Vitaly Pukhov, 2015-05-07 15:43:26

Glitch in C#, when serializing an object, you need to serialize the Form?! What to do?

There is a procedure for "saving" an object

public void Save(Dictionary<string, FileStateInfo> data, string file)
        {
            //Сохраняем резервную копию
            BinaryFormatter bf = new BinaryFormatter();
            //откроем поток для записи в файл
            using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
            using (GZipStream gz = new GZipStream(fs, CompressionMode.Compress, false))
            {
                bf.Serialize(gz, data);//сериализация
            }
        }

and the class it uses
[Serializable]
  public class FileStateInfo
    {
        int chunksize = 500000;
        public string path;
        public string shortpath;
        public long len;
        public int chunkcount;
        public Dictionary<int, Chunk> chunks = new Dictionary<int, Chunk>();
    }

dozens of times I used such a save and similar classes, and in the same program everything was fine before, but now when serializing it is required to serialize the form !? Why did it occur to him I can’t understand, maybe there are ideas why this could happen?
5f84c4ebd81e42feacf321f671ecccde.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Pukhov, 2015-05-07
@Neuroware

In general, I figured it out, there were still delegates in the class, and if a form is subscribed to them, then the ball wants to serialize it along with the object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question