I am working with the following XML schema:
<?xml version="1.0" encoding="utf-8"?><xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:uk-gcd="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21"><xs:import schemaLocation="http://resources.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21/uk-gaap-ae-2009-06-21.xsd" namespace="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21" /><xs:element id="uk-gaap-ae_NameAccountants" type="uk-gcd:nonEmptyStringItemType" name="NameAccountants" nillable="true" /></xs:schema>
When I load this schema in Visual Studio 2013's XML Schema Explorer, I can see the uk-gaap-ae_NameAccountants element and its type, which is the nonEmptyStringItemType found in the uk-gcd namespace. All is well.
However, I run into problems when I try to compile the schema within code:
var schemaReader = System.Xml.XmlTextReader.Create("my.xsd"); var thisSchema = System.Xml.Schema.XmlSchema.Read(schemaReader, null); var thisSchemaSet = new System.Xml.Schema.XmlSchemaSet(); thisSchemaSet.Add(thisSchema); thisSchemaSet.Compile();
The compilation call throws an XmlSchemaException:
System.Xml.Schema.XmlSchemaException was unhandled by user code HResult=-2146231999 Message=Type 'http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21:nonEmptyStringItemType' is not declared. Source=System.Xml LineNumber=14 LinePosition=3 SourceUri=file:///C:/Users/jferguso/Desktop/WorkItem10871.xsd StackTrace: at System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e) at System.Xml.Schema.BaseProcessor.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) at System.Xml.Schema.Compiler.CompileElement(XmlSchemaElement xe) at System.Xml.Schema.Compiler.Compile() at System.Xml.Schema.Compiler.Execute(XmlSchemaSet schemaSet, SchemaInfo schemaCompiledInfo) at System.Xml.Schema.XmlSchemaSet.Compile() at JeffFerguson.Test.Gepsio.WorkItemsTests.WorkItem10871Test() in c:\Users\JFergu99\Source\Workspaces\gepsio\JeffFerguson.Test.Gepsio\WorkItemsTests.cs:line 108 InnerException:
Why does the type appear correctly in Visual Studio but cannot be found during compilation?