Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure service bus "send" throws Operation is not valid due to the current state of the object

I'm not sure what has changed but all of a sudden I get an "InvalidOperationException - Operation is not valid due to the current state of the object". My code has definitely worked previously and I can't remember changing anything.

I'm using Microsoft.Azure.ServiceBus 4.1.3

I tried some very basic code and still get the same error:

var bus = new QueueClient("Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=Manage;SharedAccessKey=xxx", "service-event");
await bus.SendAsync(new Message(Encoding.UTF8.GetBytes("{\"test\":\"hi\"}")));

Any ideas?

Edit stacktrace:

at Microsoft.Azure.ServiceBus.Core.MessageSender.<OnSendAsync>d__58.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Microsoft.Azure.ServiceBus.RetryPolicy.<RunOperation>d__19.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.ServiceBus.RetryPolicy.<RunOperation>d__19.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Azure.ServiceBus.Core.MessageSender.<SendAsync>d__45.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at TwitchEventAdapter.EventHandler.<SendEvent>d__2.MoveNext() in C:\...\EventHandler.cs:line 66
like image 540
user3713080 Avatar asked Sep 06 '20 20:09

user3713080


People also ask

What is PeekLock?

PeekLock. The peek-lock mode tells the broker that the receiving client wants to settle received messages explicitly. The message is made available for the receiver to process, while held under an exclusive lock in the service so that other, competing receivers can't see it.

What is the maximum size of a message can be stored in a Azure Service Bus queue in standard tier?

A queue message can be up to 64 KB in size. A queue may contain millions of messages, up to the total capacity limit of a storage account. Queues are commonly used to create a backlog of work to process asynchronously. For more information, see What are Azure Storage queues.

How do I enable an Azure Service Bus?

Using Azure CLI To create a queue with message sessions enabled, use the az servicebus queue create command with --enable-session set to true . To create a subscription for a topic with message sessions enabled, use the az servicebus topic subscription create command with --enable-session set to true .


1 Answers

If you're using .Net 5.0 RC2, then installing Microsoft.Azure.ServiceBus version 5.0.0 should solve the problem.

like image 115
Sean Kearon Avatar answered Sep 17 '22 11:09

Sean Kearon