C#: Does Serializable() attribute prevent passing a class instance to another form?
I have the following classes, and is trying to build a settings module for my application. But when i try to access _configurator in settingForm method i get an exception: "object reference not set to an instance of an object". Why?
[Serializable()]
public class Config
{
public Config() { }
public string ComPort
{
get
{
return comPort;
}
set
{
comPort = value;
}
}
private string comPort;
}
public partial class kineticMoldDockUserControl : UserControl
{
private settingsForm setForm = null;
private Config _cf = null;
public kineticMoldDockUserControl()
{
InitializeComponent();
_cf = new Config();
_cf.ComPort = "COM12";
}
private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!Application.OpenForms.OfType<settingsForm>().Any())
{
setForm = new settingsForm();
setForm.Show();
setForm.cf = _cf;
}
}
}
public partial class settingsForm : Form
{
Config _configutor = null;
public Config cf { get { return _configutor; } set { _configutor = value; } }
public settingsForm()
{
InitializeComponent();
try
{
MessageBox.Show(_configutor.ComPort.GetType().ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}