Asp.Net Adding Object to Database Error: Collection was modified; enumeration operation may not execute

Question: How do you resolve Asp.Net Adding Object to Database Error: Collection was modified; enumeration operation may not execute?


Please Login to see the rest of the answer

Answer: There is a chance that you are trying to instantiate a new DTO object that contains nested Objects if one of the nested objects does not have data or null values, this behaviour happens. Make sure that if you have any nested object list or any collection inside an object you are instantiating that you just leave those collections out. Do not try to populate them if you know at some point the collection might be null.


Write an Article
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2022 - ErnesTech - Privacy