You must not do this . Despite the fact that you know that XmlWriter has a Stream under it, but this is an implementation detail, and XmlWriter should not give it to you. Also, a stream can only read or write, how will you read from it?
You must pass the original stream that was used to create the XmlWriter instance in the place where you want to read the stream, if you know that the stream can be either written or read. Otherwise, you must create a new stream that will read the content written by XmlWriter .
source share