Causas consecutivas de serialización XML: Token StartElement en estado EndRootElement daría como resultado un documento XML no válido

Estoy escribiendo en el archivo la serialización XML del objeto, generada porvalidator.MatchPossiblyValid(string input)método. Primera llamada, serializa y escribe en el archivo. Sin embargo, la segunda llamada falla con una excepción:System.InvalidOperationException: 'Token StartElement in state EndRootElement would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment. '

XmlSerializerNamespaces emptyNS = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
var serializer = new XmlSerializer(typeof(PDPCustomerInfoInvalid));
var settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
//settings.Indent = true;
using (var stream = new System.IO.StreamWriter(args[1], true))
{
    using (var writer = XmlWriter.Create(stream, settings))
        {

                serializer.Serialize(writer, validator.MatchPossiblyValid("STRING FOR PARSING"), emptyNS);
                stream.Write(Environment.NewLine);
                stream.Flush();
                //Line below throws the exception
                serializer.Serialize(writer, validator.MatchPossiblyValid("STRING FOR PARSING"), emptyNS);
                stream.Write(Environment.NewLine);
                stream.Flush();

        }
}

Respuestas a la pregunta(1)

Su respuesta a la pregunta