Hello,
I am doing this initialization :
this.oXmlDoc=new XmlDocument();
in InitializeComponent() function.
And once in a while because of some reason I can't detect this statement
is being erased and I get the Object not initialized error.
Why is this happens?
Thank you!
Do I understand you right: You manually add this.oXmlDoc=new XmlDocument();
to the InitializeComponent() method?
If so, maybe you should read the comment above InitializeComponent() which
says:
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
So as it says: "do not modify the contents of this method".
The reason is that: when you design your form the designer places generated
code into this method. As soon as you add stuff there by hand the designer
doesn't really know anything about it and changes are good that it gets
lost by the time just because the designer deletes it.
So instead of placing your line of code in the InitializeComponent() method
you should place it in the constructor. AFTER the call to
InitializeComponent(). e.g.:
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.oXmlDoc=new XmlDocument();
}
hth