Size restriction on MemoryStream

Just wondering if there is an upper limit on how many bytes you can write to a MemoryStream.

Yep there’s a limitation. In theoritical aspect CLR does not allow to allocate more than 700kB for an object on the heap. Therefore your memory stream can not be larger.

In practice due to memory fragmentation, the limit is lower (I used to have CLR E OUT OF MEMORY before 600kB).