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

Viewed 3433

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
2 Answers

Changing project version from .NET 5.0 to .NET core 3.1 solved the problem.

Related