I have the following problem: when I run my application, the settings are loaded from the file, so deserialized when this happens, I got the following error:
{"End of Stream encountered before parsing was completed."} System.Exception {System.Runtime.Serialization.SerializationException}
Serialization code:
using(FileStream write = new FileStream(SETTINGSPATH,FileMode.Create,FileAccess.Write) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(write,settings); }
Deserialization Method:
using (FileStream read = new FileStream(SETTINGSPATH,FileMode.Open,FileAccess.Read)) { BinaryFormatter formatter = new BinaryFormatter(); read.Position = 0; settings = (Settings)formatter.Deserialize(read); // settings is declared as Settings object }
Settings Class:
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Text; namespace Serie_Counter.Overkoepelend { public delegate void SelectedMoveOptionChanged(AutoMoveOption selectedOption, int checkInterval = 30 ); public delegate void EnableAutoMoveChanged(bool EnableAutoMove); [Serializable] public class Settings { private string serieListSavePath; private bool autoStart; private bool enableRember; private bool closeWithMainForm; private int warningDelay;
Does anyone know why this is happening?
If you need more information or code, please check http://seriescounter.codeplex.com/
hello Thomas
EDIT: Could the problem be that deserialization fails because I am serializing events? I just tested this, making sure that when serialized, the events are zero. and so far the error has not been repeated.
http://seriescounter.codeplex.com/SourceControl/changeset/changes/12646
source share