Encountered the same problem. I guess XmlWriter doesn't have time to flush all it's content into stream. So you should manually call
xmlWriter.Flush(); xmlWriter.Close();
Then problem is gone.