Home > Net >  Encountered an error in traverse XML node InvalidOperationException: Operation is not valid due to t
Encountered an error in traverse XML node InvalidOperationException: Operation is not valid due to t

Time:11-03

The code below

 
IEnumerator Date_SingleSIOPropertySave (string SIOName Dictionary ValueDic)
{
//first traversal root xmlnode target node
XmlNode lookForNode=null;
Foreach (XmlNode item in currnetSIOXml. FirstChild..childnodes)
{
The if (item Name==SIOName)
{
LookForNode=item;
break;
}
}
Yield return 0;
//find the target entry after traversal entry under the properties of the entry

Foreach (XmlNode child in lookForNode..childnodes)
{
//traverse a property would traverse a dictionary key to find corresponding key attribute node and at the end of the processing time of break end cycle
Foreach (var Key in valueDic. Keys)
{
If (Key==child. Name)
{
XmlElement newProperty=currnetSIOXml. The CreateElement method (Key);
LookForNode. ReplaceChild (newProperty, child);
break;
}
}
}
}


An error in line 16 error information is InvalidOperationException: Operation is not valid due to the current state of the object

Forget each great god gives guidance thank you very much

CodePudding user response:

Remove the

CodePudding user response:

Remove

CodePudding user response:

Already solve itself, thought is xmlnode class have any special usage, the original reason in line 24, that is to say, this code when traversing a xmlnodelist and try to remove and replace the elements in the list, and in the process of traversing this kind of operation is not allowed,
  •  Tags:  
  • C#
  • Related