You are currently offline, waiting for your internet to reconnect

BUG: Type "###" is not declared in reference to local type of an included XSD Schema file

This article was previously published under Q317611
The current implementation of XSD schema-validation support in the .NET framework does not convert the targerNamespace of the local referencing type of an included XSD (it does not support the "chameleon" include). For example, the following a.xsd file includes the b.xsd and c.xsd files:
<xsd:schema xmlns:xsd=""  	targetNamespace="test">	<xsd:include schemaLocation="b.xsd" />	<xsd:include schemaLocation="c.xsd" /></xsd:schema>				
Inside b.xsd, a testType type is defined:
<xsd:schema xmlns:xsd="">	<xsd:simpleType name="testType">		<xsd:restriction base="xsd:string">			<xsd:enumeration value="test"/>		</xsd:restriction>	</xsd:simpleType></xsd:schema>				
Inside c.xsd, test is declared with the testType type:
<xsd:schema xmlns:xsd="">	<xsd:element name="test" type="testType"/>             <!-- this fails, but it should not fail --></xsd:schema>				
The following error message is returned with the a.xsd schema file:
"Type 'testType' is not declared." in c.xsd
To work around this problem, add a xmlns="test" namespace declaration to the c.xsd file, for example:
<xsd:schema xmlns:xsd="" xmlns="test">	<xsd:element name="test" type="testType" xmlns="test"/>              </xsd:schema>				
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Steps to Reproduce the Problem

  1. Save the preceding a.xsd file in the c:\temp folder. Save the b.xsd and c.xsd files under the same folder as a.xsd.
  2. Create a C# console Project.
  3. Replace the code the is inside the Class1.cs file with following code:
    using System;using System.IO;using System.Xml;using System.Xml.Schema;namespace ValidationTest{	class Sample	{		public static void Main()		{			try			{				XmlSchemaCollection sc = new XmlSchemaCollection();				sc.Add("test", "c:\\temp\\a.xsd");                                Console.WriteLine("No Schema error.");						}			catch(XmlSchemaException ex)			{				Console.WriteLine("XSD schema Error: {0}", ex.Message);			}						Console.Read();		}	}}					
  4. Compile and then run the project. In the console window, the following error message is returned:
    XSD schema Error: Type 'test' is not declared. An error occurred at file:///c:/temp/c.xsd(2, 3).
  5. Open the c.xsd file, and then add xmlns="test" to the xsd:element, for example:
    <xsd:element name="test" type="test" xmlns="test"/>					
  6. Compile and then run the project. In the console window, the following output is returned:
    No Schema error.

Article ID: 317611 - Last Review: 02/12/2007 20:39:58 - Revision: 6.4

  • Microsoft .NET Framework Class Libraries 1.0
  • Microsoft .NET Framework Class Libraries 1.1
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • kbvs2002sp1sweep kbbug kbenv KB317611