question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] ServiceBus.Core.MessageSender.OnSendAsync throws "InvalidCastException: Unable to cast object of type 'Microsoft.Azure.Amqp.Framing.Accepted' to type 'Microsoft.Azure.Amqp.Transaction.Declared'."

See original GitHub issue

Describe the bug

ServiceBus.Core.MessageSender.OnSendAsync is occasionally throwing the exception “System.InvalidCastException: Unable to cast object of type ‘Microsoft.Azure.Amqp.Framing.Accepted’ to type ‘Microsoft.Azure.Amqp.Transaction.Declared’.”

Expected behavior

No InvalidCastException is thrown. If this is an error due to how I’m using the library, something more descriptive than an AMQP cast exception is thrown so that I can fix how I’m calling the library/service.

Actual behavior (include Exception or Stack Trace)

Here’s an exception stack trace excerpt. Everything after the “…” is Polly retry code or my service’s code:

System.InvalidCastException: Unable to cast object of type 'Microsoft.Azure.Amqp.Framing.Accepted' to type 'Microsoft.Azure.Amqp.Transaction.Declared'.
   at Microsoft.Azure.ServiceBus.Core.MessageSender.OnSendAsync(IList`1 messageList)
   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.MessageSender.SendAsync(IList`1 messageList)
   at Polly.AsyncPolicy.<>c__DisplayClass40_0.<<ImplementationAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
...

To Reproduce

Unknown. This happens occasionally when our service tries to add items to a Service Bus queue. I can provide more details, but I would appreciate some guidance on what you’re looking for.

Environment:

  • Name and version of the Library package used:
  • Hosting platform or OS and .NET runtime version:
    • .NET Core version 3.1.0 (commit 157910edee) with runtimes:
      • Microsoft.AspNetCore.App 3.1.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
      • Microsoft.NETCore.App 3.1.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
    • Running on Azure Kubernetes Service with
      • Kubernetes version 1.14.8
      • Linux kernel version “4.15.0-1089-azure #<span/>99~16.04.1-Ubuntu SMP Fri Jun 5 15:30:32 UTC 2020 x86_64 GNU/Linux”
  • IDE and version : N/A (exception is encountered when running under Azure Kubernetes Service, not an IDE)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
yvgopalcommented, Jun 25, 2021

We couldn’t yet reproduce it on our end. There is something going wrong with AMQP library, in a particular corner case. I just couldn’t reproduce it so far and don’t see any particular code path that may have caused this. We will keep this open, and continue to investigate as a low priority item. In the meantime, if any of you can consistently reproduce it and identify a reproducible pattern, we will be happy to fix it.

0reactions
jsquirecommented, Jul 24, 2023

@JoshLove-msft : From the most recent report, it looks as if this can be reproduced on Azure.Messaging.ServiceBus. Would you please take a look and transfer to the AMQP repo if it turns out to be in the AMQP lib?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot AMQP errors in Azure Service Bus
You see this error when a new AMQP connection is created but a link isn't created within 1 minute of the creation of...
Read more >
Azure Service Bus Connection issue - Microsoft Q&A
One of the test there is sending a message to azure service bus. The problem is when calling topicClient sendasyc it is getting...
Read more >
AMQP 1.0 in Azure Service Bus and Event Hubs protocol ...
This section explains the basic usage of AMQP 1.0 with Azure Service Bus, which includes creating connections, sessions, and links, and ...
Read more >
Microsoft.Azure.ServiceBus.ServiceBusTimeoutException ...
I have problem with Azure Service Bus integration and hope you can ... ExceptionDispatchInfo.Throw() at Microsoft.Azure.Amqp.AsyncResult.
Read more >
c# - InvalidCastException: Unable To Cast Objects of type [ ...
and I got the following error: 'CustomMembershipUser.explicit operator CustomMembershipUser (System.Web.Security.MembershipUser)': user-defined ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found