all groups > dotnet xml > april 2005 >
You're in the

dotnet xml

group:

XPathNodeList.Count throws exception in .Net v2.0


XPathNodeList.Count throws exception in .Net v2.0 Sébastien Ros
4/26/2005 2:12:02 AM
dotnet xml: During the process of an XML document, I have to make a SelectNodes() call on
an XmlDocument. It returns an isntance of XPathNodeList. I can call it
several times but at one point, the result can't be iterated.

Here is the code:

XmlNodeList nodes = _Document.SelectNodes(myXpathQuery);
foreach(XmlNode n in nodes)
{ ... }

While debugging, a NullReferenceException is thrown, but the cursor points
to the keyword "in" in the the foreach statement. It means that it occured in
the internal Enumerator. Moreover, if I put a breakpoint before the foreach
statement and try to watch into "nodes", the Count property evaluation throws
this NullReferenceException. The second time I evaluate the "Count"
everything it returns 0 (although it should be 2).

Unfortunately, if I take the same document with the same xpath query in a
virgin console application, I can't reproduce it, ecerything is ok.

Any advice is welcome.

--
Sébastien Ros
Re: XPathNodeList.Count throws exception in .Net v2.0 Ion Vasilian
4/26/2005 10:42:38 AM
Hi,

Would it be possible to provide a simple repro, complete with the xml file?
It is hard to diagnose the problem otherwise. In the least, it would be very
helpful to have the call stack from the machine where the problem occurs.
Regards,

Ion

[quoted text, click to view]

RE: XPathNodeList.Count throws exception in .Net v2.0 Sébastien Ros
4/27/2005 3:12:56 PM
It occurs when I make an xpath query using the id() operator, but it doesn't
occur everytime. It can take several other queries on this document before it
occurs.

Here are the details:

Exception:
System.NullReferenceException {"Object reference not set to an instance of
an object."}

Source :
System.Xml

StackTrace :
at System.Xml.XmlDocument.GetElementById(String elementId)
at System.Xml.DocumentXPathNavigator.MoveToId(String id)
at MS.Internal.Xml.XPath.IDQuery.ProcessIds(String val)
at MS.Internal.Xml.XPath.IDQuery.advance()
at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
at MS.Internal.Xml.XPath.XPathNodeList.ReadUntil(Int32 index)
at MS.Internal.Xml.XPath.XmlNodeListEnumerator.MoveNext()

The code executed when it occured: (the debugger points the "in", so it
happens in SelectNodes() )

string xPath = "id('230b2b34-8eb4-408e-a817-4c055525bafa')";
foreach(XmlNode n in _Document.SelectNodes(xPath))
{
...
}

The xml document:

<!DOCTYPE USS[
<!ELEMENT USS (Entity*)>
<!ELEMENT Entity (Reference*, Attribute*)>
<!ELEMENT Reference EMPTY>
<!ELEMENT Attribute (#PCDATA)>
<!ATTLIST Entity
Type CDATA #REQUIRED
Id ID #REQUIRED
[quoted text, click to view]
<!ATTLIST Reference
Role CDATA #REQUIRED
RefId IDREF #REQUIRED
[quoted text, click to view]
<!ATTLIST Attribute
Type CDATA #REQUIRED
Name CDATA #REQUIRED
[quoted text, click to view]
]>
<USS>
<Entity Type="EPT:Priority" Id="b55b67a9-a941-4a25-bea0-22c5dd2ccebf">
<Attribute Name="Name" Type="System.String">3 - Urgent</Attribute>
</Entity>
<Entity Type="EPT:State" Id="b96d364d-aa9d-4dc3-a468-78d66ac050d9">
<Attribute Name="Description" Type="System.String">The case is new and
active</Attribute>
<Attribute Name="Name" Type="System.String">Opened</Attribute>
<Attribute Name="ClosesCase" Type="System.Boolean">False</Attribute>
</Entity>
<Entity Type="EPT:Priority" Id="51b3d245-cd32-4396-8553-18f77398d666">
<Attribute Name="Name" Type="System.String">If Time</Attribute>
</Entity>
<Entity Type="EPT:Category" Id="1a672d3a-a8d2-49b6-9de6-52ff69b275fb">
<Attribute Name="Name" Type="System.String">Request</Attribute>
<Attribute Name="Bitmap"
Type="System.String">~/images/app/email.gif</Attribute>
</Entity>
<Entity Type="EPT:Priority" Id="fb04e846-d592-4650-bb24-4ea905c8d8ce">
<Attribute Name="Name" Type="System.String">1 - Urgent</Attribute>
</Entity>
<Entity Type="EPT:State" Id="b8ad8d84-c580-49fc-9ea1-6c3a8e85141e">
<Attribute Name="ClosesCase" Type="System.Boolean">True</Attribute>
<Attribute Name="Description" Type="System.String">The case had no sense
and is no more active</Attribute>
<Attribute Name="Name" Type="System.String">Closed</Attribute>
</Entity>
<Entity Type="EPT:Priority" Id="e23411d3-fc09-4ded-b6f1-95e22f7a0915">
<Attribute Name="Name" Type="System.String">2 - Urgent</Attribute>
</Entity>
<Entity Type="EPT:State" Id="c62bbb33-1d43-4a5a-ad4d-8aabf16bf205">
<Attribute Name="Name" Type="System.String">Resolved</Attribute>
<Attribute Name="ClosesCase" Type="System.Boolean">True</Attribute>
<Attribute Name="Description" Type="System.String">The case was
solved</Attribute>
</Entity>
<Entity Type="EPT:Project" Id="adf6b7d7-96ef-4418-8028-5b7d7bbbc758">
<Attribute Name="Name" Type="System.String">EUSS</Attribute>
<Reference Role="Cases" RefId="230b2b34-8eb4-408e-a817-4c055525bafa" />
<Reference Role="Cases" RefId="230b2b34-8eb4-408e-a817-4c055525bafa" />
<Reference Role="Cases" RefId="230b2b34-8eb4-408e-a817-4c055525bafa" />
</Entity>
<Entity Type="EPT:Priority" Id="8743a910-aff9-4589-aab9-e849d68b90f6">
<Attribute Name="Name" Type="System.String">Undefined</Attribute>
</Entity>
<Entity Type="EPT:Category" Id="166d7c81-b924-4022-83d3-829b6abbaf92">
<Attribute Name="Bitmap"
Type="System.String">~/images/app/feature.gif</Attribute>
<Attribute Name="Name" Type="System.String">Feature</Attribute>
</Entity>
<Entity Type="EPT:Project" Id="243200bf-953f-4d25-a76e-644ac4ccd43f">
<Attribute Name="Name" Type="System.String">Project Tracker</Attribute>
</Entity>
<Entity Type="EPT:Category" Id="b5b5b603-9ca2-42a6-976e-8b1982f80ab6">
<Attribute Name="Name" Type="System.String">Bug</Attribute>
<Attribute Name="Bitmap"
Type="System.String">~/images/app/bug.gif</Attribute>
</Entity>
<Entity Type="EPT:Priority" Id="6d127939-1b5b-4fe6-98e0-02ae6ea6bf57">
<Attribute Name="Name" Type="System.String">Useless</Attribute>
</Entity>
<Entity Type="EPT:Case" Id="230b2b34-8eb4-408e-a817-4c055525bafa">
<Attribute Name="Creation" Type="System.DateTime">4/27/2005 7:53:47
PM</Attribute>
<Attribute Name="Opened" Type="System.Boolean">True</Attribute>
<Attribute Name="Description" Type="System.String">
</Attribute>
<Attribute Name="End" Type="System.DateTime">4/27/2005 12:00:00
AM</Attribute>
<Attribute Name="Category" Type="System.String">Feature</Attribute>
<Attribute Name="Name" Type="System.String">New Case</Attribute>
<Attribute Name="State" Type="System.String">Opened</Attribute>
<Attribute Name="Priority" Type="System.String">Undefined</Attribute>
</Entity>
</USS>

Re: XPathNodeList.Count throws exception in .Net v2.0 Ion Vasilian
4/28/2005 12:49:50 PM
Hi again,

Although we couldn't reproduce the issue that you see intermittently,
the stack trace was good enough to point us to what seems to be a
potential problem on our side. We think it was related to the removal
of elements with ids from the tree. The patched code will be available
with the next beta release of the framework. Thanks for reporting the
issue. Regards,

Ion

[quoted text, click to view]

AddThis Social Bookmark Button