If you need to read the data from MemoryStream, always use ToArray() method instead of GetBuffer() method.
string Output = Encoding.UTF8.GetString(mstream.ToArray());
MemoryStream.GetBuffer() method returns the entire allocated buffer (even the unused buffer) and with ” padding for the unused buffer space.
Enjoy!!!
Advertisement