How to Serialize Class with System.Net.IPAddress Attribute?

  • Thread starter Thread starter O.B.
  • Start date Start date
O

O.B.

I have a an attribute within a Serializable class that is of type
System.Net.IPAddress. When I try to serialize the class, I get the
following error:

System.InvalidOperationException: Cannot serialize member
'SerializationTest.ConfigurationProperties.ConnectionAddress' of type
'System.Net.IPAddress', see inner exception for more details.

System.InvalidOperationException: System.Net.IPAddress cannot be
serialized because it does not have a parameterless constructor.

What workarounds are there?
 
O.B. said:
I have a an attribute within a Serializable class that is of type
System.Net.IPAddress. When I try to serialize the class, I get the
following error:

System.InvalidOperationException: Cannot serialize member
'SerializationTest.ConfigurationProperties.ConnectionAddress' of type
'System.Net.IPAddress', see inner exception for more details.

System.InvalidOperationException: System.Net.IPAddress cannot be
serialized because it does not have a parameterless constructor.

What workarounds are there?

Well, one workaround is to change the type from IPAddress to a string.
That seems to work for now. If there is something better, please let me
know.
 
Hello,
What workarounds are there?

You could implement ISerializable, which allows you to completely redefine
the process of serialization and store data in whatever format you like.
You could then use a string or an integer (or a few integers, if you're
thinking IPv6) to store the IP address data and reconstruct it on the
deserialization side.


Oliver Sturm
 
Back
Top