0

Ok, I have a class intended to manage Azure cloud queue messages, the insertions are working fine:

    public async void Insert(string message)
    {
        await Queue.AddMessageAsync(new CloudQueueMessage(message));
    }

Note that this Queue is a CloudQueue instance.

This is the message inserted in the storage using the above method

This is the message inserted in the storage using the above method

But, while trying to Get or Peek messages, a weird behavior is happening and I can't read anything of the content:

The content of the message is throwing an exception and is being returned as null

The content of the message is throwing an exception and is being returned as null.

This is the messageCount value

This is the messageCount value.

Here's textually, the method used to retrieve the messages:

    public async Task<List<string>> GetMessages()
    {
        var list = new List<string>();

        await Queue.FetchAttributesAsync();
        int messageCount = Queue.ApproximateMessageCount ?? 0;

        if (messageCount == 0) return list;

        foreach (var msg in await Queue.GetMessagesAsync(messageCount))
        {
            
             list.Add(msg.AsString);
        }

        return list;
    }

EDIT: I checked as pointed in the approved answer and figured out that I was using a deprecated package that seems to work no longer. Deprecated package This library has been split in multiple parts and is deprecated.

I had to use a most recent API and change my code, it's actually easier to use but a certain rework was needed. It's now working, and the way to use the queue in this new version (.NET v12) is documented here.

Ramon Dias
  • 835
  • 2
  • 12
  • 23
  • Can you edit your question and include the complete stack trace. Also what's the value for `messageCount`? – Gaurav Mantri Jul 15 '20 at 15:32
  • OK. Actually I could not access the stack trace using that popup. Also, the `messageCount` is returning `1`. I will see if I can get the stack and then put both of them in the question. Thanks! – Ramon Dias Jul 15 '20 at 15:39
  • Just put your `foreach` block inside a `try/catch` block and you should be able to see the stack trace. – Gaurav Mantri Jul 15 '20 at 15:45
  • I tried but it doesn't catch. I think it's being handled internally. – Ramon Dias Jul 15 '20 at 15:55
  • The latest releases can be found here: https://aka.ms/azsdk/releases - All of the new packages start with "Azure.", not "Microsoft." – Jon Gallant Jul 15 '20 at 16:08

2 Answers2

2

I believe it's related to wrong (legacy) Nuget Package. I've faced a problem like this recently and it was solved when I've upgraded to the following Packages:

Install-Package Microsoft.Azure.Storage.Common -Version 11.1.7
Install-Package Microsoft.Azure.Storage.Queue -Version 11.1.7

https://www.nuget.org/packages/Microsoft.Azure.Storage.Queue/

https://www.nuget.org/packages/Microsoft.Azure.Storage.Common/

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
0

I also faced this issue. You should update all your packages to their latest versions and it will work fine.

Anil C
  • 1,045
  • 3
  • 16
  • 38