Serialize object to XmlDocument
In order to return useful information in SoapException.Detail for an asmx web service, I took an idea from WCF and created a fault class to contain said useful information. That fault object is then serialised to the required XmlNode of a thrown SoapException . I'm wondering whether I have the best code to create the XmlDocument - here is my take on it: var xmlDocument = new XmlDocument(); var serializer = new XmlSerializer(typeof(T)); using (var stream = new MemoryStream()) { serializer.Serialize(stream, theObjectContainingUsefulInformation); stream.Flush(); stream.Seek(0, SeekOrigin.Begin);