From http://msdn.microsoft.com/en-us/library/system.io.memorystream%28v=VS.90%29.aspx:
Memory streams created with an unsigned byte array provide a
non-resizable stream of the data. When using a byte array, you can
neither append to nor shrink the stream, although you might be able to
modify the existing contents depending on the parameters passed into
the constructor. Empty memory streams are resizable, and can be
written to and read from.
When provided a reference to a MemoryStream (or even just a Stream), how can one check if it’s resizable?
The situation arose when using the OpenXML SDK, which requires the streams passed to it be resizable. I can ensure resizability by deep copying to a resizable stream, I’m just wondering if there’s a particular reason why the library doesn’t throw an exception when a bad parameter is passed to it (i.e. an unresizable stream).
Here’s one kinda ugly way were you catch the NotSupportedException when attempting to resize.