Large messages padded causes issues with DataContractSerializer


See discussion [discussion:53237]
The issue seems to happen in MsmqTransport.cs, line 220:
var payload = new MemoryStream();
StreamHelper.CopyStream(msmqMessage.BodyStream, payload);
result.Payload = payload.GetBuffer();
The issue is that the MemoryStream allocates (in our case) 128 kB and then when you call GetBuffer() you get the full 128 kB, even if the message itself is only 70 kB. We only notices this on DataContractSerializer. Our quick fix is to update the first line above with this:
var payload = new MemoryStream((int)msmqMessage.BodyStream.Length);
We're not sure if there are any issues of asking the BodyStream for its length before you read it, but it works fine so we assume the fix is correct. Obviously we want to minimize the number of in-memory buffers that get allocated and copied.

file attachments

Closed Apr 30, 2010 at 1:31 AM by HakanL