Recently I came across the error "Collection was modified after the enumerator was instantiated" and I have no idea why. The error specifies the web.config. What causes this error?
I haven't been able to reproduce it. The error pops up very seldom and random. My program takes in a file and processes it. When I receive this error I simply rerun the program and it is fine.
I'm thinking something is modifying my web.config while my program is running? My program does connect to several databases (sql, db2 and oracle) so at times it can take several seconds to complete. Could something touching the web.config during that time be the cause or am I looking at the wrong area?
Edit:
Here is some additional information about the error:
Type : System.Configuration.ConfigurationErrorsException, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Message : An error occurred loading a configuration file: Collection was modified after the enumerator was instantiated. (<path>\web.config line 59)
Source : System.Configuration
Help link :
BareMessage : An error occurred loading a configuration file: Collection was modified after the enumerator was instantiated.
Filename : <path>\web.config
Line : 59
Errors : System.Configuration.ConfigurationException[]
Data : System.Collections.ListDictionaryInternal
Looking at the stack trace it happened when I tried to read a connection string from the web.config and line 59 contains the connection string information that is being read.
Does this still look like it's due to modifying a collection in a loop?
I do add items to a collection but not in a loop and nowhere near where the stack trace is showing. I don't remove any items from collections.