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

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

O.B.

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.
 
O

Oliver Sturm

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top