Fix NRE in XmlSerializer to keep consistent behavior