I try to receive the number of retries in a ServiceBusTrigger: (from a servicebusqueue)
using Microsoft.Azure.Functions.Worker;
[Function("SyncQueue")]
public async Task HandleSyncEvent([ServiceBusTrigger("sync-events", Connection = "ServiceBus-ConnectionString")] string syncEvent, FunctionContext context)
{
var retryCount = context.RetryContext?.RetryCount ?? 0;
if (retryCount > 0) {}
}
But while the RetryContext
is not null the underlying Properties (RetryCount
, MaxRetryCount
) throw a NullreferenceException when I try to access them.
Can I solve this without wrapping a try..catch around the property when there are no retries?
Stacktrace:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Azure.Functions.Worker.Grpc
StackTrace:
at Microsoft.Azure.Functions.Worker.Grpc.GrpcRetryContext.get_RetryCount()
at cse.Functions.HandleSyncQueue.<HandleSyncEvent>d__2.MoveNext() in C:\git\backend\services\src\Synchronization\cse.Functions\HandleSyncQueue.cs:line 26