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!