I have a simple class that is marked as Serializable, and it happens to have an event. I tried to mark the event member as NonSerialized, however the compiler complains. Yet when I go to serialize the class instance, the BinaryFormatter throws an exception that the event is non serializable. Does that mean you can't serialize classes that have events? If so, then the compiler should say so up front.
Stream file = File.Open("f", FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
object obj = null;
try
{
obj = bf.Deserialize(file);
}
catch (System.Runtime.Serialization.SerializationException e)
{
MessageBox.Show("De-Serialization failed : {0}", e.Message);
}
file.Close();
System.Collections.ArrayList nodeList = obj as System.Collections.ArrayList;
foreach (TreeNode node in nodeList)
{
treeView.Nodes.Add(node);
}
Fails to work on the following class:
[Serializable()]
class Simple
{
private int myInt;
private string myString;
public event SomeOtherEventDefinedElsewhere TheEvent;
}