Cannot access a closed Stream of a memoryStream, how to reopen?

Solution 1:

You can clone the original one and then use the clone, even when the original has been closed. Even though the original one is created with a capacity of 1000, ToArray() returns a 2 element array. ToBuffer() on the other hand gets you the entire buffer, which is what you don't want.

MemoryStream original = new MemoryStream(1000);
original.WriteByte(4);
original.WriteByte(5);

MemoryStream dolly = new MemoryStream(original.ToArray());
dolly.Seek(0, SeekOrigin.Begin);

Solution 2:

try this:

memoryStream = new MemoryStream(memoryStream.ToArray());

Solution 3:

How can I reopen a closed memory stream?

You can't reopen the stream. If you need to "reset" the stream, just assign it a new instance:

memoryStream = new MemoryStream();