private void WriteXml(XmlWriteAdaptor writer) { Debug.Assert(writer.XmlWriter.WriteState == WriteState.Element, "Invalid WriteState: " + writer.XmlWriter.WriteState); writer.WriteClass(Type); // XML element names should normally being with a lowercase letter, but we want to preserve the // case of all the property names. if (HelpLink != null) { writer.WriteElement("HelpLink", HelpLink); } if (Message != null) { writer.WriteElement("Message", Message); } if (Source != null) { writer.WriteElement("Source", Source); } if (StackTrace != null) { writer.WriteElement("StackTrace", StackTrace); } if (TargetSite != null) { writer.WriteElement("TargetSite", TargetSite); } writer.WriteElement("HResult", HResult); // Additional properties (defined on derived exception classes) WriteDictionaryToXml(writer, _properties, "additionalProperties"); // Inner exception if (InnerException != null) { writer.WriteStartElement("innerException"); InnerException.WriteXml(writer); writer.WriteEndElement(); // </innerException> } }