4

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.AsyncTaskMethodBuilder1+AsyncStateMachineBox1[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.

Rakesh Kumar
  • 2,701
  • 9
  • 38
  • 66
  • Have you reviewed dealing with this error message, e.g. https://stackoverflow.com/questions/7397207/json-net-error-self-referencing-loop-detected-for-type – Noah Stahl Jul 19 '20 at 17:03
  • According to the error message, it is obvious that the error is not on the cosmosdb UpdateItemAsync side, you can breakpoint to debug and locate. – Jason Pan Jul 21 '20 at 02:16
  • Can you actually pinpoint the piece of code that it throwing the error and the code path it follows, You've posted 4 different methods here without actually saying where it errors. – MindingData Dec 18 '20 at 05:28

0 Answers0