public void Serialize <T>(Stream stream, T message, SerializerTypeMapper typeMapper) where T : class { using (var outputStream = new NonClosingStream(stream)) using (var streamWriter = new StreamWriter(outputStream)) using (XmlWriter writer = XmlWriter.Create(streamWriter, _writerSettings)) { SerializeMessage(message, writer, new SerializerContext(typeMapper)); } }