BUG: Your application may stop responding when you use the XmlReader.ReadToNextSibling method in Visual Studio 2005 (906724)



The information in this article applies to:

  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Express Edition

Bug #: 402878 (SQLBUDT)

SYMPTOMS

Consider the following scenario. In Microsoft Visual Studio 2005, you use the XmlReader.ReadToNextSibling method in the System.Xml namespace to advance the XmlReader object to the next sibling element. The value of the ReadState property of the XmlReader object is ReadState.Initial (ReadState Enumeration). In this scenario, an internal infinite loop may occur, and your application may stop responding (hang).

CAUSE

The XmlReader.ReadToNextSibling method is a virtual method on the XmlReader base class. This issue may occur on all XmlReader-based objects that do not override this method. These objects include the XmlTextReader object, the XmlNodeReader object, and the objects that are returned by the XmlReader.Create method.

An XmlReader object is in initial state right after the object has been created and before the Read method is called for the first time. In this scenario, the ReadState property on the XmlReader object is set to ReadState.Initial.

WORKAROUND

To work around this issue, you must run the Read method of the XmlReader object before you use the XmlReader.ReadToNextSibling method. This operation can move the XmlReader object out of the initial state.

The following helper function provides a functional replacement for the XmlReader.ReadToNextSibling method. You can work around the issue by using a function that is similar to the function in the following code sample.
public static bool ReadToNextSibling( XmlReader r, string name ) {
	if ( r.ReadState == ReadState.Initial ) {
		r.Read();
		if ( r.IsStartElement( name ) ) {
			return true;
		}
	}
	return r.ReadToNextSibling( name );
}

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

Modification Type:MajorLast Reviewed:11/14/2005
Keywords:kbpending kbbug KB906724 kbAudDeveloper