Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.net - Serializing a class that has events
    primarykey
    data
    text
    <p>Sigh... I have a class that has properties that have events. The event is fired when a property has changed in value. The instance of the class is a backer for the information on a form. I need to save the information that is in the form for later recall.</p> <p>The idea here is to bind the properties as datasources to the textboxes and datagridview on the form. That is the driver for the event to update the textbox or datagridview when the value of the class changes.</p> <p>So...when I use the following code to save a file of a static variable (test) it works fine: </p> <pre><code>Dim test As String = "Hello" ' Persist to file Dim save As New SaveFileDialog If save.ShowDialog = Windows.Forms.DialogResult.OK Then Dim stream As FileStream = File.Create(save.FileName) Dim formatter As New BinaryFormatter() formatter.Serialize(stream, test) stream.Close() End If </code></pre> <p>If I try it using the instance of the class that backs the data it is throwing errors because of the class has events:</p> <pre><code>Dim test As new ClassWithEvents() ' Persist to file Dim save As New SaveFileDialog If save.ShowDialog = Windows.Forms.DialogResult.OK Then Dim stream As FileStream = File.Create(save.FileName) Dim formatter As New BinaryFormatter() formatter.Serialize(stream, test) stream.Close() End If </code></pre> <p>The error:</p> <blockquote> <p>Type 'System.Windows.Forms.Form' in Assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.</p> </blockquote> <p>All I really want to do is keep the values of the controls on a form for later recall.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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