Skip to main content
  1. Posts/

IPAddress class serializable?

Back in 2002 I posted a question in Usenet about the IPAddress class being serializable, but not serializing in ASP.NET. I just found the post, and noticed that no one responded with the reason why:

There are two types of serialization in .NET: System.Runtime.Serialization and System.Xml.Serialization. Runtime serialization uses the SerializableAttribute while XML serialization does not. The attribute is irrelevant for XML serialization, which is used by ASP.NET.

The error I received was:

System.Net.IPAddress cannot be serialized because it does not have a default public constructor

One of the requirements of the XmlSerializer is that the type being serialized must have a default public constructor. So the answer is:

Yes, it’s serializable using runtime serialization, but not XML serialization.

2006: With .NET 3.0, DataContracts are used by newer serialization engines and are now preferred over the SerializableAttribute.

2019: System.Text.Json includes new attributes to control JSON serialization.

Attributes from the System.Runtime.Serialization namespace aren’t supported in System.Text.Json.
George Tsiokos
Author
George Tsiokos

Comments

You should crosspost this to the newsgroup. Remember, Google is forever. ;-)
So is george.tsiokos.com. :)
I will come five years from now and we’ll talk.
Jason Jackson
Well, its almost 5 years after your posting and its still here.
Al Dunstan
Ok, so now it’s April of 2009 and you still can’t serialize an IPAddress with XmlSerializer. Now what?
J West
So? Did he show? Was there a talk?
8 D
Nick
5 years later…
Nice! You had posted the same on USENET after all, two years before this weblog entry (unless, of course, the dates here are wrong).
Matt Dunlap
Ran into this problem too and would love a solution.

Leave a comment

Preview

Comments are reviewed before publishing.