[Mono-bugs] [Bug 51941][Wis] New - Unhandled Exception (NullReferenceException) raised from MoveToNextAttribute when SelectSingleNode called

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 9 Dec 2003 12:39:49 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by wmavis@thinktmr.com.

http://bugzilla.ximian.com/show_bug.cgi?id=51941

--- shadow/51941	2003-12-09 12:39:48.000000000 -0500
+++ shadow/51941.tmp.19479	2003-12-09 12:39:49.000000000 -0500
@@ -0,0 +1,123 @@
+Bug#: 51941
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System.XML
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: wmavis@thinktmr.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Unhandled Exception (NullReferenceException) raised from MoveToNextAttribute when SelectSingleNode called
+
+Description of Problem:  
+  
+The combination of creating an element, appending an attribute to the  
+element, appending the element to a document, and selecting the node by  
+the attribute is causing problems if you specify a attribute value that  
+does not match.  
+  
+Steps to reproduce the problem:  
+  
+1. Compile and run:  
+  
+using System;  
+using System.Xml;  
+  
+class xml  
+{  
+        static void Main()  
+        {  
+                XmlDocument doc;  
+                XmlNode node;  
+  
+                doc = new XmlDocument();  
+                doc.LoadXml("<Nodes />");  
+  
+                // Add an element to our xml  
+                node = doc.CreateElement("Node");  
+                node.Attributes.Append(doc.CreateAttribute("name"));  
+                node.Attributes.GetNamedItem("name").InnerText =  
+"FirstNode";  
+                doc.FirstChild.AppendChild(node);  
+  
+                // Get the element we just added  
+                node = doc.FirstChild.SelectSingleNode("Node[@name =  
+'FirstNode']");  
+                if(node != null) Console.WriteLine("node.OuterXml: " +  
+node.OuterXml);  
+  
+                // Get an element that does not exist (!!!THIS FAILS!!!)  
+                node = doc.FirstChild.SelectSingleNode("Node[@name =  
+'SecondNode']");  
+                if(node != null) Console.WriteLine("node.OuterXml: " +  
+node.OuterXml);  
+  
+                // Add another element to our xml  
+                node = doc.CreateElement("Node");  
+                node.Attributes.Append(doc.CreateAttribute("name"));  
+                node.Attributes.GetNamedItem("name").InnerText =  
+"SecondNode";  
+                doc.FirstChild.AppendChild(node);  
+  
+                // Debug  
+                Console.WriteLine("doc.OuterXml: " + doc.OuterXml);  
+  
+                // Get the element we just added (!!!THIS FAILS!!!)  
+                node = doc.FirstChild.SelectSingleNode("Node[@name =  
+'SecondNode']");  
+                if(node != null) Console.WriteLine("node.OuterXml: " +  
+node.OuterXml);  
+  
+                // Debug  
+                Console.WriteLine("doc.OuterXml: " + doc.OuterXml);  
+        }  
+}  
+  
+  
+Actual Results:  
+  
+node.OuterXml: <Node name="FirstNode" />  
+  
+Unhandled Exception: System.NullReferenceException: A null value was found  
+where an object instance was required  
+in <0x0008d> System.Xml.XmlDocumentNavigator:MoveToNextAttribute ()  
+in <0x00059> System.Xml.XPath.AttributeIterator:MoveNext ()  
+in <0x0008d> System.Xml.XPath.AxisIterator:MoveNext ()  
+in <0x002b9> System.Xml.XPath.EqualityExpr:EvaluateBoolean  
+(System.Xml.XPath.BaseIterator)  
+in <0x0017d> System.Xml.XPath.PredicateIterator:MoveNext ()  
+in <0x0007a> System.Xml.XmlNode:SelectSingleNode  
+(string,System.Xml.XmlNamespaceManager)  
+in <0x00019> System.Xml.XmlNode:SelectSingleNode (string)  
+in <0x00163> .xml:Main ()  
+  
+  
+Expected Results:  
+  
+node.OuterXml: <Node name="FirstNode" />  
+doc.OuterXml: <Nodes><Node name="FirstNode" /><Node  
+name="SecondNode" /></Nodes>  
+node.OuterXml: <Node name="SecondNode" />  
+doc.OuterXml: <Nodes><Node name="FirstNode" /><Node  
+name="SecondNode" /></Nodes>  
+  
+How often does this happen?   
+  
+Always  
+  
+Additional Information:  
+  
+If you just LoadXML:  
+  <Nodes>  
+    <Node name="FirstNode" />  
+    <Node name="SecondNode" />  
+  </Nodes>  
+SelectSingleNode works fine, so I assume it has to do with the dynamic  
+creation and appending of the Element/Attribute.