Herman Schoenfeld
Herman Schoenfeld

Reputation: 8724

XML Serialization to use empty array instead of NULL

I have a property

 [XmlElement]
 public string[] Emails { get; set; }

which is initialized as string[0] at constructor.

If I XML serialize and deserialize a default instance of this object, the property is NULL.

How can I tell the XML Serializer to use an empty array instead of NULL for this property?

Upvotes: 6

Views: 3220

Answers (1)

dba
dba

Reputation: 1175

5 years later... :) Replacing Array with List<> did the trick for me.

[XmlElement (IsNullable = false)]
public List<string> Emails {get;set;}

Upvotes: 8

Related Questions