private void DeserializeObj() { FileStream fileStream = File.OpenRead(System.Environment.CurrentDirectory + @"\Data\Test.tsd"); try { IFormatter formatter = (IFormatter)Activator.CreateInstance (typeof(BinaryFormatter)); formatter.Context = new StreamingContext (StreamingContextStates.File | StreamingContextStates.Persistence); fileStream.Position = 0; MainObject obj = (MainObject)formatter.Deserialize(fileStream); mainObj = obj; } finally { if (fileStream != null) { fileStream.Dispose(); fileStream = null; } } }
public Form1() { InitializeComponent(); mainObj = new MainObject(); }