FIX: You may experience the System.StackOverflowException error when you open an XML document that contains a deeply nested XML document in the .NET Framework 1.1 and in the .NET Framework 1.0 (884021)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0

SYMPTOMS

You may experience the System.StackOverflowException error when you open an XML document that contains a deeply nested XML document. Additionally, your application may fail. This problem may occur in the Microsoft .NET Framework 1.1 and in the .NET Framework 1.0.

CAUSE

You may experience the System.StackOverFlowException error when you use the System.Xml.XmlDocument class to try to open an XML document that contains a deeply nested XML document.

RESOLUTION

To resolve this problem, obtain the latest .NET Framework 1.1 post-Service Pack 1 XML Web services and XML Messaging hotfix rollup package.

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

890673 Availability of the .NET Framework 1.1 post-Service Pack 1 XML Web services and XML Messaging hotfix rollup package 8

STATUS

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

MORE INFORMATION

Steps to reproduce the problem

Run the following code.
using System.Xml;
using System;
using System.IO;
using System.Text;
using System.Reflection;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace NestXML
{
	class Class1
	{
		static void Main(string[] args)
		{
			const int NODE_DEPTH = 20000;
			int i;
			Console.WriteLine ( "The deeply nested XML file is being created.");
			File.Delete( "deep.xml" );
			StreamWriter streamWriter = File.CreateText( "deep.xml" );
			streamWriter.Write("<?xml version='1.0' ?>");
			for ( i=1; i<=NODE_DEPTH; i++ )
			{
				streamWriter.Write( "<N_" + i.ToString() + ">" );
			}
			for ( i=NODE_DEPTH; i>=1; i-- )
			{
				streamWriter.Write( "</N_" + i.ToString() + ">" );
			}
			streamWriter.Close();
			
			XmlDocument doc = new XmlDocument();
			doc.PreserveWhitespace = true;
			try
			{
				doc.Load( new XmlTextReader( "deep.xml" ) );
				Console.WriteLine( "The deep.xml file has been successfully loaded." );
			}
			catch ( Exception ex )
			{
				Console.WriteLine( "The deep.xml file could not be loaded. The exception follows:" );
				Console.WriteLine ( ex.Message );
			}
			Console.WriteLine( "Press ENTER to exit." );
			Console.ReadLine();
		}
	}
}

Modification Type:MajorLast Reviewed:4/7/2006
Keywords:kbQFE KBHotfixServer kbtshoot kbfix KB884021 kbAudDeveloper