I have a similar problem, but slightly different. When I use the Crainiate class Model in my form, it works fine:
private void InitializeComponent()
{
this.theModel = new Crainiate.ERM4.Model();
}
private void buttonTest_Click(object sender, EventArgs e)
{
try
{
MemoryStream theStream = new MemoryStream();
theStream.Seek(0, SeekOrigin.Begin);
theModel.Save(theStream, SaveFormat.Binary);
theStream.Seek(0, SeekOrigin.Begin);
theModel.Open(theStream, LoadFormat.Binary);
}
catch (Exception exception)
{
MessageBox.Show(exception.ToString());
}
}
If I press buttonTest, it works fine without any problems.
Now if I make a derived model class to override some protected methods like this:
public class MyModel : Model
{
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (keyData == System.Windows.Forms.Keys.Delete)
{
// Do something here.
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}
}
And I change my form to instantiate this derived class:
private void InitializeComponent()
{
this.theModel = new MyModel() as Crainiate.ERM4.Model;
}
Now if I call buttonTest, I get an exception on the Save method:
exception = {"Type '..MyModel' in Assembly 'MyAssembly, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable."}
Now if I mark my model class with the [Serializable] attribute, then the exception I get on Save is :
exception = {"Type 'Crainiate.ERM4.Model' in Assembly 'Crainiate.ERM4, Version=4.1.2665.32214, Culture=neutral, PublicKeyToken=df8e50c7fad67e61' is not marked as serializable."}
What do I need to do with my derived model to get it to serialize and deserialize?
Thanks,
Jim