Azure-sdk-for-net: [BUG] Azure Service Bus Queue (RegisterMessageHandler) not working on .NET 5.0 Preview 7

Created on 1 Aug 2020  ·  13Comments  ·  Source: Azure/azure-sdk-for-net

Describe the bug
An exception is thrown repeatedly on exceptionReceivedHandler after calling queueClient.RegisterMessageHandler when running .Net 5.0.
The exact same project runs fine on .Net Core 3.1.

Expected behavior
No exception thrown

Actual behavior (include Exception or Stack Trace)
Following exception is thrown repeatedly

Message handler encountered an exception System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.OnReceiveAsync(Int32 maxMessageCount, TimeSpan serverWaitTime)
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.<>c__DisplayClass64_0.<<ReceiveAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func`1 operation, TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func`1 operation, TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.ReceiveAsync(Int32 maxMessageCount, TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.ReceiveAsync(TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.MessageReceivePump.<MessagePumpTaskAsync>b__11_0().

To Reproduce
Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)

  1. Using Visual Studio 16.7.0 Preview 6.0 with .NET SDK 5.0.100-preview.7 installed, follow the instructions from Receive messages from the queue
  2. Make sure the target framework for the project is net5.0
  3. Make sure that the ConnectionString and QueueName constants are valid (The queue does not need to contain any messages)
  4. Start Debugging

Environment:
Microsoft.Azure.ServiceBus 4.1.3
Visual Studio 16.7.0 Preview 6.0
.NET SDK 5.0.100-preview.7.20366.6

Client Service Attention Service Bus customer-reported needs-team-attention question

All 13 comments

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jfggdl, @axisc.

Tagging and routing to the team best able to assist.

//cc: @JoshLove-msft, @MiYanni

Experiencing the exact same issue. Switching project from 3.1 to 5 (with no other changes) starts generating this error. All our services use Service Bus, so this is a blocker to us trying 5 atm.

Subscribed.

I'm having the same issue trying to send a message with MessageSender.SendAsync(message), also using Microsoft.Azure.ServiceBus 4.1.3 and .NET SDK 5.0.100-preview.7.20366.6.

The same code works as expected in .NET Core 3.1.

Debugging the issue using symbols from Microsoft Symbol Server and attempting to send a message using a .NET SDK 5.0.100-preview.7.20366.6 console application and Microsoft.Azure.ServiceBus 4.1.4 results in the following stack trace when the InvalidOperationException is thrown.

System.InvalidOperationException
HResult=0x80131509
Message=Operation is not valid due to the current state of the object.
Source=Microsoft.Azure.Amqp
StackTrace:
at Microsoft.Azure.Amqp.Transport.TransportStream.Flush()
at System.IO.Stream.<>c.b__39_0(Object state) in /_/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs:line 239
at System.Threading.Tasks.Task.InnerInvoke() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 2381
at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 2360
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 289
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 57

This exception was originally thrown at this call stack:
Microsoft.Azure.Amqp.Transport.TransportStream.Flush()
System.IO.Stream.FlushAsync.AnonymousMethod__39_0(object) in Stream.cs
System.Threading.Tasks.Task.InnerInvoke() in Task.cs
System.Threading.Tasks.Task..cctor.AnonymousMethod__277_0(object) in Task.cs
System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, object) in ExecutionContext.cs
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in ExceptionDispatchInfo.cs

//cc: @xinchen10 for expertise on the Microsoft.Azure.Amqp library, and @sjkwak for awareness.

14068 seems like it may be the same underlying cause.

Dead on previewing .NET 5 preview 8 because of this as well. First project I converted hit this.

Are there plans to release a fixed package soon?

Workaround: TransportType=AmqpWebSockets

Installing version 2.4.6 of Microsoft.Azure.Amqp fixed the issue on my side

The version 5.0.0 of Microsoft.Azure.ServiceBus available on Nuget uses the fixed version of Microsoft.Azure.Amqp.
I believe this issue can now be closed.

Was this page helpful?
0 / 5 - 0 ratings