Note that there are some explanatory texts on larger screens.

plurals
  1. POBinary Serialization, I think I almost have it working
    primarykey
    data
    text
    <p>I've been following a guide on Binary Serialization (this one here: <a href="http://www.codeproject.com/Articles/1789/Object-Serialization-using-C" rel="nofollow">http://www.codeproject.com/Articles/1789/Object-Serialization-using-C</a>) and I think I finally almost have it working. When I save the file is created, but when I try to load, nothing is loaded. I feel like I'm close to getting this working. Any advice would be appreciated. Here's the code:</p> <p>Save/Load class</p> <pre><code>[Serializable()] public class SaveLoad : ISerializable { public int GameDay = Date.GameDay; public List&lt;Adventurer&gt; Adventurers = FormMain.AdventurerManager.AdventurerList; public SaveLoad() { GameDay = 0; Adventurers = null; } public SaveLoad(SerializationInfo info, StreamingContext ctxt) { GameDay = (int)info.GetValue("Date", typeof(int)); Adventurers = (List&lt;Adventurer&gt;)info.GetValue("Adventurers", typeof(List&lt;Adventurer&gt;)); } public void GetObjectData(SerializationInfo info, StreamingContext ctxt) { info.AddValue("Date", GameDay); info.AddValue("Adventurers", Adventurers); } } </code></pre> <p>Save/Load methods:</p> <pre><code> void btnSaveGame_Click(object sender, EventArgs e) { SaveLoad save = new SaveLoad(); Stream stream = File.Open("SaveGame.osl", FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, save); stream.Close(); } void btnLoadGame_Click(object sender, EventArgs e) { SaveLoad load = new SaveLoad(); Stream stream = File.Open("SaveGame.osl", FileMode.Open); BinaryFormatter bformatter = new BinaryFormatter(); load = (SaveLoad)bformatter.Deserialize(stream); stream.Close(); Date.CalculateDate(); this.Visible = false; ((FormMain)(this.ParentForm)).ControlMainScreen.Visible = true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload