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();
}
}