.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Collection was modified; enumeration operation might not execute.

Posted By:      Posted Date: August 30, 2010    Points: 0   Category :ASP.Net
Hi,            i'm trying to update my dataset. I want to finad a particaular value from dataset, and bind it to exch and every record of Dataset The code i'm using to update the dataset is: Dap.SelectCommand = Cmd Dap.Fill(DS)Dim pRow As DataRow For Each pRow In DS.Tables(0).RowsField1 = pRow("StoreName").ToString() Field2 = Convert.ToDouble(pRow("abc")) + Convert.ToDouble(pRow("sds")) + Convert.ToDouble(pRow("sdczs")) - ((Convert.ToDouble(pRow("xcvx"))) + (Convert.ToDouble(pRow("xcv"))) + (Convert.ToDouble(pRow("xvc"))))Dim row As DataRow = DS.Tables(0).NewRow() row("Field2") = MarginDS.Tables(0).Rows.Add(row) DS.AcceptChanges() Dap.Update(DS) ' ================================== ' ===> Bind Values To Web Chart <=== ' ================================== WebChartControl1.Visible = True WebChartControl1.DataSource = DS WebChartControl1.SeriesDataMember = "Field1" WebChartControl1.Series(0).ArgumentDataMember = "Field1" WebChartControl1.Series(0).ValueDataMembers.Item(0) = "Field2" WebChartControl1.DataBind() Next When i tried to execute the code i got the error saying  'Collection was modified; enumeration operation might not execute.' Can you pl .help in fixing the pr

View Complete Post

More Related Resource Links

Modifying a list results in "Collection was modified; enumeration operation may not execute"



I am trying to add a list column as well as assign a value to the list column which is newly created in the document libraries available in the site. After the value is assigned, when the second document library is about to iterate, I am getting an error as "Collection was modified; enumeration operation may not execute".

Below is the code i have used:


SPListCollection mylists = currentweb.GetListsOfType(SPBaseType.DocumentLibrary);
 foreach (SPList list in mylists)
 if (!list.Hidden)
AddField("CustomColumn", SPFieldType.Text, list.Fields);
 fieldCol.View.DefaultView = true;
int mouas = 5;
SPFolder folder;
folder.Item["CustomColumn"] = mouas;


How to rectify this?

Thank you

Collection was modified; enumeration operation may not execute.



I have the following foreach loop:



foreach (string variable in _variables.Keys)double fx = ObtieneValorParametro(variable, poliza, periodo);if (_variables[variable] == null)




_variables[variable] = fx;


Where _variables is of Dictionary<string, object> type.

The only modification to the collection I'm making is to change the value of an element from null to a value, as you see. I'm not removing nor adding elements, so, why I receive that error? I tried by using a traditional for loop, but since the collection is a Dictionary<string, object> collection I couldn't access the elements by mean of their indices.

Collection was modified; enumeration operation may not execute.


foreach(RepeaterItem rptitem in  rptroot.Items)
                if (rptitem.ItemIndex == 0)
                    RepeaterItem headerItem = new RepeaterItem(rptitem.ItemIndex, ListItemType.Header);
                RepeaterItem repeaterItem = new RepeaterItem(rptitem.ItemIndex, ListItemType.Item);
                Label lbl = new Label();
                CheckBox Chkroot = new CheckBox();
                lbl.Text = string.Format(" <b> {0} <br />",
                parentID = Convert.ToInt32(rptRootValues.Tables[0].Rows[rptitem.ItemIndex]["IdApplication"].ToString());
                repeaterItem = new RepeaterItem(rptitem.ItemIndex, ListItemType.Separator);
                LiteralControl ltrlHR = new LiteralControl();
                ltrlHR.Text = "<br/>";
                ListItem li = new ListItem();
                rptroot.ItemDataBound += new RepeaterItemEventHandler(rptroot_ItemDataBound);
                rptroot.DataSource = rptRootValues;

"Collection was modified; enumeration operation may not execute" errors while crawling BCS .NET conn



I've been examining a problem where sharepoint 2010 search creates the following kind of errors when crawling external system created using .NET connector:
"Error while crawling LOB contents. ( Collection was modified; enumeration operation may not execute. )"

The error seems to occur randomly for about 0.5% of all the crawled items. Sharepoint log shows the following line:
10/22/2010 17:31:49.30     mssdmn.exe (0x36AC)                         0x0460    SharePoint Server Search          FilterDaemon                      e4ye    High        FLTRDMN: Errorinfo is "Collection was modified; enumeration operation may not execute."  [fltrsink.cxx:553]  d:\office\source\search\native\mssdmn\fltrsink.cxx     

If a visual studio debugger is attached to the mssdmn.exe when the exception is thrown, the call stack looks like this:
+        $exception    {"Collection wa

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)


Hey guys

I came across this bug using while trying to implement a sitemap

Line 147:						Panel panel = new Panel();
Line 148:						panel.Controls.Add(_viewState);
Line 149:						Page.Form.Controls.Add(panel);
Line 150:						string script = "document.getElementById('" + _viewState.ClientID + "').value = GetViewState__AspNetTreeView('" + Extender.MakeChildId("UL") + "');";
Line 151:						Page.ClientScript.RegisterOnSubmitStatement(typeof(TreeViewAdapter), _viewState.ClientID, script);

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +8696951
   CSSFriendly.TreeViewAdapter.SaveAdapterViewState() in E:\wwwroot\ThirdParty\CSSFriendly\CSSFriendly_24242\CSSFriendly\TreeViewAdapter.cs:149
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +8901848
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148
   System.Web.UI.Control.SaveViewStateRecursive(ViewStateMode inheritedMode) +148

Items collection cannot be modified when the DataSource property is set.

I am having two listboxes which performs Drag and Drop, when i drag and leave on to second listbox I am getting the error: Items collection cannot be modified when the DataSource property is set. code: using     System; using     System.Collections.Generic; using     System.ComponentModel; using     System.Data; using     System.Drawing; using     System.Linq; using     System.Text; using     System.Windows.Forms; namespace     WindowsControlEx8 {     public partial class Form1 : Form {     List<Colors> colors = new List<Colors>() {     new Colors{colorName="Red"},     new Colors{colorName="Green"},     new Colors{colorName="Black"},     new Colors{colorName="White"},     new Colors{colorName="Orange"} };         public Form1() { InitializeComponent();   }     private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { }     private void button1_Click(object sender, EventArgs e) {     var c = from c1 in colors     select c1.colorName; listBox1.DataSource = c.ToList();   } &nb

Multiple-step OLE DB operation generated errors in Pre-Execute

Hello, I am getting below error; what could be the reason? The input is valid adn works good if I give to a multicast for test. But I get below error when I use OLEDB Destination ("table or view fast load") as my target. Note: Columns mappings are done auto by SSIS and All looks good as my source and destination are having same names as well. [Stage - Issue [33923]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E21. An OLE DB record is available.  Source: "Microsoft SQL Native Client"  Hresult: 0x80040E21  Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". [Stage - Issue [33923]] Error: Cannot create an OLE DB accessor. Verify that the column metadata is valid. [DTS.Pipeline] Error: component "Stage - Issue" (33923) failed the pre-execute phase and returned error code 0xC0202025. Thanks, Prabhat

External Content Type - Read List Operation - "Cannot find a collection element of a supported type.


I'm trying to define External Content Type Operations for an External Content Type. I can add a Connection, Type "WCF Service" no problem. And I can define a "New Read Item Operation" using that connection.

But I can't define a "Read List Operation". I get the following error message, in the Return Parameter Configuration: "Cannot find a collection element of a supported type..." it goes on to say - see the help documentation for supported types. I can't find any help documentation on this.

I've tried returning different types in the provider web service but keep getting the same error. What are the supported types the web service can return?

The reading I've done suggests that you can connect to a non-MS web service using a connection type of "WCF Service". Is this correct? If it is what's the best soap format the web service provider should use - Doc/Literal?



The Controls collection cannot be modified


Salam to all,

when i am trying to use AjaxTabContro in my website,

when i Drag and drop Tab Control to my user control in my aspx page, the i run my aspx page, the following error appear to me:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

this is my code:

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="Plex" %>

<Plex:TabContainer ID="NewsTabContainer" CssClass="Plex__Tab"  runat="server" ActiveTabIndex="0" Visible="false"  >
    <Plex:TabPanel runat="server" ID="TabPanel1" Width="100%" Height="100%"  >


i didnot make any server side code, just when using the above HTML code the error appears,

also when i remove the TabContainer Control from my user control, the page working with no issue !!!



HttpContext.Items and Server.Transfer/Execute

The problem was basically that when a Server.Transfer call was applied the script container (and also various ClientScriptProxy script embedding routines) would potentially fail to load up the specified scripts.

want to execute url without showing that page or url to client.


hello friends,

I need ur help,what i want to do is to execute a url ("To send a text message to client") on client registration but without showing that url page, in short executing url without displaying any page or url to the client.

please help and thanks in advance.

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is no



 I keep getting the following error. I also added time out parameter in the connection stirng and it still did not help. Has any one faced similar issues.

Thanks in adavance.

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]

A lengthy operation in an ASP.NET web service


I've built an ASP.NET web service with .NET 2.0 (an asmx file). I invoke a web service method using Ajax. The method takes a substantial amount of time to execute (5 minutes to 1 hour). I believe it's not a good idea to "hang" the web request for so long.
I'm wondering if the web service method could spawn an additional process which in turn would execute the lengthy operation and notify the web service once the operation is completed.
Are there any good practices regarding this kind of functionality?


ToggleDebugCompilation fails trying to perform "an unauthorised operation"



We're having a problem with the Visual Studio 2008 RTW version of the web deployment projects on a colleagues machine. The project works fine if I run it on my machine, but when he tries to run it on his machine he gets:

<SNIP : Most output removed>
  Task "Exec"
    if exist ".\TempBuildDir\" rd /s /q ".\TempBuildDir\"
  Done executing task "Exec".
  Using "ToggleDebugCompilation" task from assembly "C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.Tasks.dll".
  Task "ToggleDebugCompilation"
    Updating Web.config <compilation> element debug attribute to 'True'.
    C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets(639,7): error : Attempted to perform an unauthorized operation.
    C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets(639,7): error MSB4018: The "ToggleDebugCompilation" task failed unexpectedly.
    C:\Program Files\MSBuild\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets(639,7): error MSB4018: System.ArgumentNullException: Parameter "message" cannot be null.
    C:\Program Files\MSBuild\Microsoft\WebDeployment

Basic Instincts: Collection and Array Initializers In Visual Basic 2010


Collection Initializers are a great addition to the language and allows concise syntax in order to initialize both framework and user defined collection types.

Spotty Bowles

MSDN Magazine October 2009

UI on the Fly: Use the .NET Framework to Generate and Execute Custom Controls at Run Time


Creating UI controls on the fly can be accomplished via run-time code generation. And there are lots of reasons to do so. Generating these controls once and then reusing them as needed is more efficient than generating the controls each time. Read on.

Morgan Skinner

MSDN Magazine December 2005

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend