ServiceBusMessageBatch.TryAddMessage(ServiceBusMessage) Method


Attempts to add a message to the batch, ensuring that the size of the batch does not exceed its maximum. If the message is modified after being added to the batch, the batch will fail to send if the modification caused the batch to exceed the maximum allowable size. Therefore it is best to not modify a message after adding it to the batch.

public bool TryAddMessage (Azure.Messaging.ServiceBus.ServiceBusMessage message);
member this.TryAddMessage : Azure.Messaging.ServiceBus.ServiceBusMessage -> bool
Public Function TryAddMessage (message As ServiceBusMessage) As Boolean



The message to attempt to add to the batch.



true if the message was added; otherwise, false.


When a batch is sent, it will be locked for the duration of that operation. During this time, no messages may be added to the batch. Calling TryAdd while the batch is being sent will result in an InvalidOperationException until the send has completed.

Occurs when the message has a member in its ApplicationProperties collection that is an unsupported type for serialization. See the ApplicationProperties remarks for details.

Applies to