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
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.
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.
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 .
If you're using .Net 5.0 RC2, then installing Microsoft.Azure.ServiceBus version 5.0.0 should solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With