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?

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.


Edit this Article
Collection was modified; enumeration operation may not execute Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.
Your Session is Ending
Login to Continue


© 2021 - ErnesTech - Privacy