Search code examples
azureazureservicebusazure-sdk-.net

Error while using ServiceBusProcessor - Azure.Messaging.ServiceBus SDK


I am getting an exception after the StartProcessingAsync() method. The debug pointer goes to the "ProcessorErrorAsync" method. I followed similar steps provided in the link - https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample04_Processor.md Am I missing some steps here? Exception Details: error.Exception.Message:

Method not found: 'System.Threading.Tasks.Task`1<System.Collections.Generic.IEnumerable`1<Microsoft.Azure.Amqp.AmqpMessage>> Microsoft.Azure.Amqp.ReceivingAmqpLink.ReceiveMessagesAsync(Int32, System.TimeSpan, System.TimeSpan, System.Threading.CancellationToken)'.
private void ListenerBind(string key, ServiceBusProcessorOptions onMessageOptions)
        {
            ServiceBusClient tempClient = this._cacheClient.Get(key);
            ServiceBusProcessor tempProcessor = tempClient.CreateProcessor(this._topicName, this._subscriptionName, onMessageOptions);
            try
            {
                //temp.OnMessageAsync(this.MessageProcessCallBackAsync, onMessageOptions);
                tempProcessor.ProcessMessageAsync += MessageProcessCallBackAsync;
                tempProcessor.ProcessErrorAsync += ProcessErrorAsync;
                tempProcessor.StartProcessingAsync();
            }
            catch (InvalidOperationException ex)
            {
                this._logger.Log($"{ex.Message}", EventLevel.Informational);
            }
            catch (Exception ex)
            {
                this._logger.LogException(ex);
            }
        }
        private Task ProcessErrorAsync(ProcessErrorEventArgs error)
        {
            Exception ex = new Exception(
                $" , Action {error.ErrorSource}, " +
                $" , Endpoint {error.FullyQualifiedNamespace}" +
                $",EntityPath {error.EntityPath} "
                , error.Exception);
            this._logger.LogException(ex);

            this._onErrorCallback(ex, string.Empty);

            return Task.CompletedTask;
        }

Solution

  • I actually came across this error in my project as well. My VS solution has a Windows Service that listens to the Azure Service Bus and I have a console application which acts as a "Windows Service Runner" for local debugging. I kept getting the exception mentioned in the question while running my Service Runner and it turned out that I was missing the Azure.Messaging.ServiceBus package in my Service Runner console application.