My context is .NET PCL Profile111.
I try to use the DataContractSerializer
with XmlDictionaryWriter
for binary xml serialization. The problem I have is that after I dispose of the XmlDictionaryWriter
the MemoryStream
it was writing to gets closed.
My code:
using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(outputStream))
{
DataContractSerializer serializer = new DataContractSerializer(iObject.GetType());
serializer.WriteObject(writer, iObject);
writer.Flush();
}
//outputStream is closed now.
Documentation for the XmlWriterSettings says that the CloseOutput property is false by default.
I cannot use the overload for XmlDictionaryWriter.CreateBinaryWriter
with ownsStream
parameter because it is not available in PCL.
How can I make the XmlDictionaryWriter
let the output Stream
live after the XmlDictionaryWriter
is disposed?