I am getting below error while updating items in cosmos db.
Newtonsoft.Json: Self referencing loop detected for property 'task' with type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1+AsyncStateMachineBox
1[FleetHub.Notifications.Common.Results.Dtos.ResultDto,FleetHub.Notifications.Commands.Handlers.EnableOrDisableNotificationCommandHandler+d__2]'. Path 'stateMachine.<>t__builder'.
Here is my method for update:
public async Task<ResultDto> HandleAsync(EnableOrDisableNotificationCommand command, ILogger log)
{
var subscriptions = await GetSubscriptions(command.PayerNumber);
if (subscriptions.Any())
{
await UpdateIsActive(command.IsActive.Value, subscriptions);
return new ResultDto { ResultType = ResultType.Success, Message = $"Updated IsActive status successfully for payer :{command.PayerNumber}" };
}
else
return new ResultDto { ResultType = ResultType.Success, Message = $"No item found for payer :{command.PayerNumber}" };
}
private async Task<List<Subscription>> GetSubscriptions(string payerNumber)
{
var subscriptions = await _subscriptionRepository
.GetItemsAsync(x => x.PayerNumber == payerNumber, o => o.PayerNumber);
return subscriptions.ToList();
}
private async Task UpdateIsActive(bool isActive, List<Subscription> subscriptions)
{
foreach (var subscription in subscriptions)
{
subscription.IsActive = isActive;
await _subscriptionRepository
.UpdateItemAsync(subscription.Id.ToString(), subscription);
}
}
public async Task<ItemResponse<T>> UpdateItemAsync(string id, T item)
{
return await _container.ReplaceItemAsync<T>(item, id);
}
I am using Cosmos DB SDK for CRUD operations.