I am having an issue where I have a defined IEnumerator
variable that holds some JSON stripped from an XML Document. Within the JSON, I will be stripping bits and pieces out depending on what the user wants to get rid of. However, on the second usage of the IEnumerator
, I get Operation not valid due to the current state of the object
. I know it's an issue with using it/calling it a second time because when I comment out the first usage, it works fine. However, I will eventually be calling this 3 separate times.
Sample Code
private XmlDocument deleteXml(XmlDocument xmlDoc)
{
IEnumerator theJson = xmlDoc.SelectNodes("Path/Path2").GetEnumerator();
KillNode(theJson, "one");
KillNode(theJson, "two"); //operation not valid due to the current state of the object
}
private void KillNode(IEnumerator theNodes, string nodeType)
{
while (theNodes.MoveNext())
{
XmlNode theNode = theNodes.Current as XmlNode;
switch (nodeType)
{
case "one":
//do something
break;
case "two":
//do something
break;
}
}
}
I could take the easy route and just create another IEnumerator
variable but I will have the scenario where the output of the first iteration needs to be maintained in the second iteration (and third). I'm reading some things about how I need to add a key to the config file for maxhttpkeys but I tried that and it didn't work (as expected). I think my issue is because I'm calling the IEnumerator
more than once. I'm just not sure how to solve it as I am not having any luck finding anything on SOF or google.