-1

I'm trying to serialize and object with this line:

string jsonData = JsonConvert.SerializeObject(myObj, Formatting.Indented,
       new JsonSerializerSettings
        {
             ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        });

myObj is rather a large object with many lists and properties.

My understanding is this error occurs when you are trying to iterate though an obj that has since been modified.

My question - is how can I figure out which collection is being modified? Any special command I can run in immediate window to tell me which I should focus on?

Thank you, B

Prasad Telkikar
  • 15,207
  • 5
  • 21
  • 44
bdd
  • 77
  • 1
  • 1
  • 3
  • 1
    Same here, we also can not figure out anything without seeing the class which you are trying to serialize and how are you populating it. – Chetan May 30 '18 at 01:12
  • 1
    It would be awesome if you could provide a [mcve] so we can see the code in question. – mjwills May 30 '18 at 01:40
  • What is the `StackTrace` of the exception being thrown? – mjwills May 30 '18 at 01:40
  • Possible duplicate of [Collection was modified; enumeration operation may not execute](https://stackoverflow.com/questions/604831/collection-was-modified-enumeration-operation-may-not-execute) – codebender May 30 '18 at 01:56

1 Answers1

0

If you check the stack trace in the exception being thrown you can identify the line where the error is. The collection around that line is the one that was modified.

PepitoSh
  • 1,774
  • 14
  • 13