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 8209779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:50:44+00:00 2026-06-07T09:50:44+00:00

I have the following code. private void LoopThroughDependsIssues(JIRAOperations jiraOps, string jiraURL, string token, string

  • 0

I have the following code.

private void LoopThroughDependsIssues(JIRAOperations jiraOps, string jiraURL, string token, string username, string password, string projectKey, string exportTargetPath, string branch, SVNOperations svnOps, string svnExePath, string changesetDBFile, DependencyManager mgr)
        {
            var tempVar = mgr.Dependencies;
            foreach (var item in tempVar)
            {
                if (item.depends.Length > 0)
                {
                    var templist = item.depends;
                  var  listissues1 = templist.Split(',');
                     for (var i = 0; i < listissues1.Length-1; i++)
                     {
                         var newissue1 = new string[] { listissues1[i].ToString() };
                         newissue1.getChangeSet(jiraOps, jiraURL, token, username, password, projectKey, exportTargetPath, branch, svnOps, svnExePath, changesetDBFile, mgr);
                     }
                    //throw new Exception("Dependencies found");
                }
            }
        }

In this, i am iterating through the mgr.Dependencis collection. This value is changing in newissue1.getChangeSet(jiraOps, jiraURL, token, username, password, projectKey, exportTargetPath, branch, svnOps, svnExePath, changesetDBFile, mgr);
So for every calling of this method, my collection value is increasing. But for first time it is working fine. But while iterating for second time it is giving exception as

Collection was modified; enumeration operation may not execute.

I think this exception is coming for changing the collection. How to handle this situation.?

My class definition as follows.

public class Dependency
     {
         public string issueID { get; set; }
         public string jirastatus { get; set; }
         public int dependencyFound { get; set; }
         public string depends { get; set; }
         public string linked_issues { get; set; }
       }

      public class DependencyManager
      {
          public List<Dependency> Dependencies { get; private set; }
          public DependencyManager()
          {
              this.Dependencies = new List<Dependency>();

          }
}
  • 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-06-07T09:50:46+00:00Added an answer on June 7, 2026 at 9:50 am

    If you index into the Dependencies collection there wouldn’t be an Enumerator created and you can loop through as the collection is modified. This approach could easily cause headaches if the new items are not appended to the end of the list or items are removed.

    for(int i = 0; i < mgr.Dependencies.Count; i++)
    {
      var item = mgr.Dependecies[i];
      if (item.depends.Length > 0)
      {
          // code unchanged
      }
    }
    

    A safe approach would be to use a Queue and populate it with the initial items from mgr.Dependencies and then Enqueue any additional items you want to process.

    var toBeProcessed = new Queue<Dependency>(mgr.Dependencies);
    while(toBeProcessed.Count > 0)
    {
      var item = toBeProcessed.Dequeue();
    
      // loop
    
      // if a new dependency gets added that needs processing, just add it to the queue.
      toBeProcessed.Enqueue(newissue1);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: private String foo; public void setFoo(String bar) { foo
I have the following code: private void SetControlNumbers() { string controlString = ; int
I have the following code: private void Process(string path) { using (FileStream fs =
I have the following code - private static void convert() { string csv =
I have the following code: private char[] headerToWrite; protected String workingFileName; private void writeHeaderToFile()
I have following code: private void ProcessQueue() { foreach (MessageQueueItem item in GetNextQueuedItem()) PerformAction(item);
I have the following code: private void _DoValidate(object sender, DoWorkEventArgs e) { this.BeginInvoke(new MethodInvoker(()
I have the following code: private void WatchFileForChanges() { if (fileInfo.Directory != null) {
I have the following code behind a button in Visual Studio 2010 private void
I have the following code: [TestMethod] public void TestFoo() { Foo(null); } private void

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.