I have a class library project that contains some common code between other projects in my solution. One of these shared codes involves performing XML validation against an XSD file. The XSD name is passed as a parameter to the method and then loaded using Assembly.GetFile() .
The problem is that the XSD file imports two other XSDs . I have loaded all three as resources into my class library, but from what I read, xsd: import will not work. Is there an alternative approach for making these XSDs available in my Library Library project without breaking xsd:import instructions?
Change - Update
I have implemented Alexander's suggestion below, but as I said in my comment, whenever GetEntity() is called for xs:import 'd XSD, ofObjectToReturn is null . This led to the first instance of type xs:import 'd throwing an exception of "type not defined".
To solve this problem, I modified GetEntity() to return GetManifestResourceStream() regardless of the value ofObjectToReturn . This seems to work for the first level of xs:import statements, but the secondary xs:import inside one of the original xs:import does not work. I have confirmed that GetEntity() is called for this secondary xs:import , but I get a type exception not defined for the type defined in this secondary XSD.
- TopLevel.xsd - types
- FirstLevelImport1.xsd - types allow small
- FirstLevelImport2.xsd - types
- SecondLevelImport1.xsd - type exception not defined for the type defined in this XSD
In XmlReader.Create() an "undefined" exception is thrown, which is passed to XmlReaderSettings , which determines the validation of the schema.
source share