WCF: Message.CreateBufferedCopy and maxBufferSize limit
The Problem
Message.CreateBufferedCopy takes a parameter called maxBufferSize typed as int. Why is the value here Int32.MaxValue? Technically, you can imagine WCF using as much memory as it needs (by setting the buffer pool size to 0) so why the max value?
The Answer
The maxBufferSize parameter for CreateBufferedCopy is a limit on buffer allocations rather than on message size. You can copy arbitrarily large messages through this API provided the algorithm used by the concrete Message implementation doesn't involve an in-memory representation of the message larger than this limit (e.g., by sharing a reference to an existing buffer or by reading the message from an external resettable stream). If you break the limit, then the implementation should throw a QuotaExceededException. Nearly all applications interested in copying such very large messages should use a custom Message implementation. The Int32 type reflects the 2 GB limit on the size of GC heap objects!