Is WindowsAzure.Storage.Queue compatible with dotnet core 3.1?

Viewed 328

I have migrated a project from dotnet core 2.2 to 3.1, but it seems that some parts of the code don't work as expected: task is cancelled and the call of GetMessageQueue() returns null. In a class used to perform some automated tests, I have the following method:

public static async Task<CloudQueueMessage> WaitForMessage(this CloudQueue queue, TimeSpan interval, CancellationToken ct)
        {
            var message = await queue.GetMessageAsync();
            while (message == null)
            {
                await Task.Delay(interval, ct);
                ct.ThrowIfCancellationRequested();
                message = await queue.GetMessageAsync();
            }
        }

This is how I call it:

await myObject.CallbackQueue.WaitForMessage(TimeSpan.FromSeconds(1),
                new CancellationTokenSource(TimeSpan.FromSeconds(60)).Token)

In dotnet core 2.2 CloudQueueMessage is used from Microsoft.WindowsAzure.Storage.Queue and the method returns the message, but it seems that in 3.1 there is no message returned and the task is cancelled. I have replaced the package Microsoft.WindowsAzure.Storage.Queue with Microsoft.Azure.Storage.Queue, but still the same issue.

To reproduce:

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using System;
using System.Threading;
using System.Threading.Tasks;

 public async Task Test()
        {


            CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue queue = queueClient.GetQueueReference("callbackmock");

            var message = await queue.GetMessageAsync();
            var ct = new CancellationTokenSource(TimeSpan.FromSeconds(60)).Token;
            while (message == null)
            {
                await Task.Delay(TimeSpan.FromSeconds(1), ct);
                ct.ThrowIfCancellationRequested();
                message = await queue.GetMessageAsync();
            }

        }
1 Answers

It seems the nuget you are using here is not supported in .NET Core 3.1. Pls follow Tutorial: Work with Azure Queue Storage queues in .NET and use code like below to read queue messages:

static async Task<string> RetrieveNextMessageAsync(QueueClient theQueue)
{
    if (await theQueue.ExistsAsync())
    {
        QueueProperties properties = await theQueue.GetPropertiesAsync();

        if (properties.ApproximateMessagesCount > 0)
        {
            QueueMessage[] retrievedMessage = await theQueue.ReceiveMessagesAsync(1);
            string theMessage = retrievedMessage[0].MessageText;
            await theQueue.DeleteMessageAsync(retrievedMessage[0].MessageId, retrievedMessage[0].PopReceipt);
            return theMessage;
        }

        return null;
    }

    return null;
}
Related