Hichamveo
Hichamveo

Reputation: 514

Cannot access a disposed object. Object name: 'tlsxyz'

I'm facing a random error when sending message from an Azure function to an Azure Service Bus (Standard) Topic.

the message error is:

Cannot access a disposed object. Object name: 'tls2576'., Stacktrace : at Microsoft.Azure.ServiceBus.Core.MessageSender.OnSendAsync(IList1 messageList) at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func1 operation, TimeSpan operationTimeout) at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func1 operation, TimeSpan operationTimeout) at Microsoft.Azure.ServiceBus.Core.MessageSender.SendAsync(IList1 messageList) at ServiceBusFunctions.MyTopic.Run(HttpRequest req, ILogger log, ExecutionContext context) in myAzureFunction

sometimes the object name in the error is 'tls2716'.

The code is running from an Azure function instance containing 3 functions. Tere are 2 redundant functions APP containing the same code called in round robin from an Application Gateway. The client code to send messages to the topic is:

var message = new Message(Encoding.UTF8.GetBytes(requestBody));

//Custom properties for topis routing
message.UserProperties.Add("P1", P1);
message.UserProperties.Add("P2", P2);
message.UserProperties.Add("P3", P3);


ITopicClient topicClient = new TopicClient(SBConnectionString, CCTopicName);
await topicClient.SendAsync(message);
await topicClient.CloseAsync();

thanks for your help

Upvotes: 0

Views: 934

Answers (2)

Hichamveo
Hichamveo

Reputation: 514

The problem was closing the static topic client when a conccurent call is using it. the Fix is not to close the topicclient to reuse it and minimze the number of connection and tunning performance when open a connection

Upvotes: 1

Ravi Kumar Kasim
Ravi Kumar Kasim

Reputation: 174

This happens due to accessing the disposed objected after clearing from memory.

Upvotes: 0

Related Questions