Type Reason ArgumentException The text would result in a non-well formed XML document. InvalidOperationException The XmlWriter.WriteState is WriteState.Closed.
If text is either null or String.Empty, this method writes a comment with no data content, for example <!---->.
If text contains an invalid sequence of two dashes "--" the System.Xml.XmlWriter can either throw an ArgumentException (System.Xml.XmlTextWriter objects) or insert a space between the dashes "- -" so that the text is a valid XML comment (System.Xml.XmlWriter objects created by the erload:System.Xml.XmlWriter.Create method).
For the asynchronous version of this method, see XmlWriter.WriteCommentAsync(string).