Wednesday, 26 January 2011

Memory stream is not expandable

An upgrade to .Net 4 for an MVC app highlighted an issue with the MemoryStream class we were using in the framework. Seems that unless you use the default constructor, the stream cannot be expandable. If the stream expands you'll get a lovely System.NotSupportedException: Memory stream is not expandable error thrown at you like a ninja star.

var ninjaStarStream = new MemoryStream(buffer); // Potential error
var fluffyStream = new MemoryStream(); // Stream is expandable :)

Consider yourself warned!

No comments:

Post a Comment