Microsoft KB Archive/317490

= BUG: You cannot validate an XML instance that references two schemas if the schemas circularly import each other =

Article ID: 317490

Article Last Modified on 9/15/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft .NET Framework Class Libraries 1.0
 * Microsoft .NET Framework Class Libraries 1.1

-



This article was previously published under Q317490



This article refers to the following Microsoft .NET Framework Class Library namespaces:
 * System.IO
 * System.Xml
 * System.Xml.Schema



SYMPTOMS
You receive a duplicate declaration error message under the following circumstances:
 * One Extensible Markup Language Schema Definition Language (XSD) schema (A.xsd) imports another XSD schema (B.xsd), and vice versa.
 * Both schemas are referenced in an Extensible Markup Language (XML) instance.
 * You add both schemas to the schema collection.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
This circular import problem also occurs in diamond include/imports wherein A.xsd includes A1.xsd, B.xsd includes B1.xsd, and B1.xsd imports A1.xsd. Both A.xsd and B.xsd are referenced by the same XML instance and added to the schema collection.

Steps to Reproduce the Behavior
  Create a new XSD schema named cir_imp.xsd that contains the following code:       Create a new XSD schema named circular.xsd that contains the following code:    </xsd:schema> </li>  Create a new XML instance named Test.xml that contains the following code: <c1:A xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;circular circular.xsd&quot; xmlns:c1=&quot;circular&quot;> testValue </c1:A> </li> Save cir_imp.xsd, circular.xsd, and Test.xml to drive C.</li> Start Visual Studio .NET.</li> Create a new Console Application in Microsoft Visual C# .NET.</li>  Replace the code in Class1.cs with the following code: using System; using System.IO; using System.Xml; using System.Xml.Schema;

namespace ValidationTest {   class Test {       static int _ValidationErrorsCount = 0;

public static void Main {           try {               XmlTextReader tr = new XmlTextReader(&quot;c:\\cir.xml&quot;); XmlValidatingReader vr = new XmlValidatingReader(tr);

vr.Schemas.Add(&quot;circular_import&quot;, &quot;c:\\cir_imp.xsd&quot;); vr.Schemas.Add(&quot;circular&quot;, &quot;c:\\circular.xsd&quot;); vr.ValidationType = ValidationType.Schema; vr.ValidationEventHandler += new ValidationEventHandler (ValidationHandler);

while(vr.Read); Console.WriteLine(&quot;Validation finished: {0} validation errors&quot;, _ValidationErrorsCount); }           catch(System.Xml.Schema.XmlSchemaException ex) {               Console.WriteLine(&quot;Error {0}&quot;, ex.Message); }       }

public static void ValidationHandler(object sender, ValidationEventArgs args) {           Console.WriteLine(&quot;***Validation error&quot;); Console.WriteLine(&quot;\tSeverity:{0}&quot;, args.Severity); Console.WriteLine(&quot;\tMessage :{0}&quot;, args.Message); _ValidationErrorsCount++; }   } }                    </li> Compile and run the project. Notice that the following error message appears in the console window:

Error Global element 'circular:A' has already been declared. An error occurred a t file:///c:/circular.xsd(3, 5).

</li></ol>

Keywords: kbbug kbpending kbvs2002sp1sweep KB317490

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.