Handling FormatExceptions using XmlSerializer.Deserialize

Posted by qntmfred on Stack Overflow See other posts from Stack Overflow or by qntmfred
Published on 2010-03-21T02:30:40Z Indexed on 2010/03/21 2:41 UTC
Read the original article Hit count: 465

I have a third party web service that returns this xml

<book>
  <release_date>0000-00-00</release_date>
</book>

I am trying to deserialize it into this class

public class Book
{
    [XmlElement("release_date")]
    public DateTime ReleaseDate { get; set; }
}

But because 0000-00-00 isn't a valid DateTime, I get a FormatException. What's the best way to handle this?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about xmlserializer