I'm trying to use IXmlSerializable
ReadXml
and WriteXml
methods with an XDocument
object ( using the Foo.WriteTo( ... )
and XDocument.Load( ... )
methods.
I want to store the class which implements the IXmlSerializable
interface into a variable stored within the default Application Settings class.
Trying to do this results in a pretty obnoxious failure :
This is the Settings class :
This is the class wrapping the
[Serializable]
class XmlModel : IXmlSerializable {
public XDocument _foo = new XDocument(
new XElement( "Foo",
new XElement( "Bar", "Baz" ) ) );
public XmlModel( XDocument Foo ) {
_foo = Foo;
}
public XmlSchema GetSchema( ) {
return null;
}
public void ReadXml( XmlReader reader ) {
this._foo = XDocument.Load( reader );
}
public void WriteXml( XmlWriter writer ) {
_foo.WriteTo( writer );
}
}
Aaaand this is the Program class ( I'm using just a simple console application to reproduce the issue )
class Program {
static void Main( string[ ] args ) {
if ( Settings.Default.DoUpgrade ) {
Settings.Default.Upgrade( );
Settings.Default.DoUpgrade = false;
Settings.Default.Save( );
}
Console.WriteLine( Settings.Default.Foo._foo );
Console.ReadLine( );
}
}
This exception pops up because I have all exceptions turned on, but even with them OFF, the ApplicationSettings
file isn't taking the data.
Why is this happening?