I have a MemoryStream object which is passed by Stream type parameter
(Stream is abstract class in C#).
I want to clone it to create another separate MemoryStream object with current position of the original and to create also a new XMLReader out of it, so I will be able to read its content.
This is what I did, and it’s not working (debugging the line marked with //* -> newReader has got {None} value)
Assumption: you are inside a method and have Stream currentStream reference.
var x = new XmlReaderSettings();
x.IgnoreWhitespace = true;
using (var newMemoryStream = new MemoryStream())
{
stream.CopyTo(newMemoryStream);
using (var newReader = XmlReader.Create(newMemoryStream,x)) //*
{
Doing some stuff...
}
}
I have solved my problem! 🙂
The things which were missing are marked with
//*.Here is the code as it should be: