473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XPathNodeList.Count throws exception in .Net v2.0

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
Evaluant - CTO
Nov 12 '05 #1
3 3562
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

"Sébastien Ros" <Sb*********@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
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
Evaluant - CTO

Nov 12 '05 #2
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.MoveN ext()
at MS.Internal.Xml.XPath.XPathNodeList.ReadUntil(Int3 2 index)
at MS.Internal.Xml.XPath.XmlNodeListEnumerator.MoveNe xt()

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
<!ATTLIST Reference
Role CDATA #REQUIRED
RefId IDREF #REQUIRED <!ATTLIST Attribute
Type CDATA #REQUIRED
Name CDATA #REQUIRED

]>
<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>

Thank you
Nov 12 '05 #3
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

"Sébastien Ros" <Sb*********@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
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.MoveN ext()
at MS.Internal.Xml.XPath.XPathNodeList.ReadUntil(Int3 2 index)
at MS.Internal.Xml.XPath.XmlNodeListEnumerator.MoveNe xt()

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
<!ATTLIST Reference
Role CDATA #REQUIRED
RefId IDREF #REQUIRED

<!ATTLIST Attribute
Type CDATA #REQUIRED
Name CDATA #REQUIRED

]>
<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>

Thank you

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian | last post by:
Create a simple MDI form and a child form, and try the following simple code to add a new menu item on the Edit menu popup: private void editMenu_Popup(object sender, System.EventArgs e) {...
16
by: ChInKPoInt [No MCSD] | last post by:
I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a way to force the C# compiler to catch possible exception? In Java, all exceptions thrown MUST BE caught, otherwise...
0
by: Michael Conroy | last post by:
Hi... Synposis... Throws exception: "Specified argument was out of the range of valid values." Read on for the juicy tidbits. MySimpleClassCol mscc=new MySimpleClassCol(); private void...
0
by: guy | last post by:
i have a method which throws an exception. the thing i dont understand is that the only change between the two versions is a line of code AFTER the one that throws the exception - see code below...
5
by: Sridhar | last post by:
Hi, I have created a web application. I have a data access dll to interact with database. I added this dll as a reference to the web application. Now let's say if I am calling a function in data...
3
by: Nindi73 | last post by:
Hi, I am in need of a deep copy smart pointer (Boost doesn't provide one) which doesnt require the contained types to have a virtual copy constructor. I wrote a smart pointer class that I think...
6
by: Fir5tSight | last post by:
Hi, What does "throw" do? I understand that it throws an error when certain exceptional situation happens. My guess is that this *ignores* the error and *continues* so that it prevents the...
4
by: HaifaCarina | last post by:
here's the complete lines of errors.. Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at...
1
by: jimgym1989 | last post by:
I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException this is my code /** * @(#)textFileRead.java * * * @author * @version 1.00 2008/10/17 */
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.