A
Andrus
While iterating a collection it is not allowed to remove its element.
However code below runs *without* (!) error in .NET 2.0 and 3.5
There could be some buggy IEnumerable implementation that fails to report
errorneous
removal of collection content
Please confirm, is this .NET bug ?
Andrus.
using System;
using System.Windows.Forms;
using System.Xml;
public class Test
{
[STAThread]
static void Main()
{
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.PreserveWhitespace = false;
xDoc.LoadXml(xml);
XmlNodeList list = xDoc.SelectNodes("//comment()");
foreach (XmlNode node in list)
{
node.ParentNode.RemoveChild(node);
}
}
catch (Exception ex)
{
Clipboard.SetText(ex.ToString());
MessageBox.Show(ex.ToString());
}
}
const string xml = @"<?xml version=""1.0"">
<Report><!-- --></Report>
";
}
However code below runs *without* (!) error in .NET 2.0 and 3.5
There could be some buggy IEnumerable implementation that fails to report
errorneous
removal of collection content
Please confirm, is this .NET bug ?
Andrus.
using System;
using System.Windows.Forms;
using System.Xml;
public class Test
{
[STAThread]
static void Main()
{
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.PreserveWhitespace = false;
xDoc.LoadXml(xml);
XmlNodeList list = xDoc.SelectNodes("//comment()");
foreach (XmlNode node in list)
{
node.ParentNode.RemoveChild(node);
}
}
catch (Exception ex)
{
Clipboard.SetText(ex.ToString());
MessageBox.Show(ex.ToString());
}
}
const string xml = @"<?xml version=""1.0"">
<Report><!-- --></Report>
";
}