Cannot close stream until all bytes are written – C#
This error is raised when the position of stream or memory stream object is set at the end of stream. To resolve the issue either you can set the position to “o” as shown below.
MemoryStream ms = new MemoryStream(); // Your memory stream
If this doesn’t work, you can re-create the memory stream as shown below
MemoryStream content =new MemoryStream(); // Your memory stream.
MemoryStream ms = new MemoryStream(ReadFully(content)); // New memory stream
public static byte ReadFully(Stream input)
byte buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
ms.Write(buffer, 0, read);
age renew reviewsays:
This website really has all of the information I needed
about this subject and didn’t know who to ask.