G
Guest
How might I serialize an IPAddress?
I read it needs to have a default constructor so I made a wrapper class:
[Serializable]
public class IPAddressEx : IPAddress
{
public IPAddressEx()
: base( IPAddress.None.GetAddressBytes() )
{
}
public IPAddressEx( byte[] address )
: base( address )
{
}
public static IPAddressEx Convert( IPAddress address )
{
IPAddressEx toReturn = new IPAddressEx(
address.GetAddressBytes() );
return toReturn;
}
}
But I still get an error when I serialize this IPAddressEx:
There was an error generating the XML document.
When I execute this code to serialize:
XmlSerializer serializer = new XmlSerializer( typeof(
Printers.IPAddressEx ) );
XmlWriter output = XmlWriter.Create( configPath );
serializer.Serialize( output, new Printers.IPAddressEx() );
Thanks,
Chris
I read it needs to have a default constructor so I made a wrapper class:
[Serializable]
public class IPAddressEx : IPAddress
{
public IPAddressEx()
: base( IPAddress.None.GetAddressBytes() )
{
}
public IPAddressEx( byte[] address )
: base( address )
{
}
public static IPAddressEx Convert( IPAddress address )
{
IPAddressEx toReturn = new IPAddressEx(
address.GetAddressBytes() );
return toReturn;
}
}
But I still get an error when I serialize this IPAddressEx:
There was an error generating the XML document.
When I execute this code to serialize:
XmlSerializer serializer = new XmlSerializer( typeof(
Printers.IPAddressEx ) );
XmlWriter output = XmlWriter.Create( configPath );
serializer.Serialize( output, new Printers.IPAddressEx() );
Thanks,
Chris