2
votes

When trying to add a message to an Azure Service Bus Queue, Sometimes I'm getting this error. Can anyone please explain why this happens?

enter image description here

The setup is, We have an Azure durable function that invokes an activity function. That activity function adds this message to the queue.

Here's how we do the queuing.

    public async Task SendWithDelayAsync<T>(T obj, TimeSpan delayProcessing, string sessionId = null) where T : BaseQueueMessage
    {
        string messageBody = JsonConvert.SerializeObject(obj);
        var message = new Message(Encoding.UTF8.GetBytes(messageBody));
        if (!string.IsNullOrEmpty(sessionId))
        {
            message.SessionId = sessionId;
        }
        // Send the message to the queue.
        await _queueClient.ScheduleMessageAsync(message, DateTime.Now.Add(delayProcessing));
    }

Thanks!

2

2 Answers

0
votes

As mentioned in the docs , this happens when,

An attempt is made to invoke an operation on an object that has already been closed, aborted, or disposed. In rare cases, the ambient transaction is already disposed.

Resolution is to Check the code and make sure it doesn't invoke operations on a disposed object.

I had similar issue in the past, may be try upgrading Microsoft.Azure.WebJobs.Extensions.ServiceBus SDK version to "4.1.2" if you are not using the same.

0
votes

Please try including this into your code. This would give you an idea whether the client is closed

if (_client.IsClosedOrClosing)
{
   _queueClient= new QueueClient(connectionString, queueName);
}