Best way to check message size before sending


NServiceBus v6.3.4

Hi Everyone, I am trying to send a message which is under the 4MB size limit of MSMQ. I first serialize the payload object using JsonConvert.SerializeObject(obj) and check its length. If it’s greater than 3.5MB, then I convert the object to byte[] and set the message DataBus Property otherwise I leave it alone.

I then do a context.Send() and immediately get a failed to send Message to addres: xxxx
System.Messaging.MessageQueueException: Insufficient resources to perform operation.

NSB does create header information for the message but it’s not 500k. Am I checking the size of the message correctly before I send it over the line?

Any help would be greatly appreciated.

Just as a side note, if I do place the object into the Databus property, the message goes through the bus just fine. It writes the file to the Databus directory but the size of the message is still under 4MB.

Thanks in advance.

(Indu Alagarsamy) #2


Can you elaborate your use case on the need to perform a check on the size?
Would it be a problem just to use data bus as is?

Other alternatives to DataBus is a community backed project:

Indu Alagarsamy
Particular Software