Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:33:27+00:00 2026-05-12T07:33:27+00:00

Recently I came across the error Collection was modified after the enumerator was instantiated

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:33:27+00:00Added an answer on May 12, 2026 at 7:33 am

    You cannot change a collection while iterating over it (i.e. in a foreach).

    So, adding or removing items from a collection while within the foreach block will cause this error.

    As an error in web.config it might be that you are adding a duplicate key that is defined elsewhere, or that you are trying to change the config dynamically in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I came across this error in my WCF trace: There was an error
I've been learning about error handling in PHP recently and came across the error_log()
I recently came across a question somewhere: Suppose you have an array of 1001
I came across some code recently that used a custom error handler to turn
I recently came across this web page http://www.yoda.arachsys.com/csharp/readbinary.html explaining what precautions to take when
I put together a test table for a error I recently came across. It
I recently came across the subject of exact real arithmetic after reading this paper
I recently came across this error in IE9 that says :- The maximum number
I recently came across Phonegap . Have anyone of you tried it. Its an
I recently came across a situation where I have to do some actions when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.