Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported files are not processed correctly #49

Closed
datguy opened this issue Feb 20, 2018 · 1 comment
Closed

Imported files are not processed correctly #49

datguy opened this issue Feb 20, 2018 · 1 comment

Comments

@datguy
Copy link

datguy commented Feb 20, 2018

I have several schemas that use shared types defined in another schema. I can generate these with a single run of xsd.exe, but it doesn't provide some of the features I need.

> xsd -c -f shared.xsd main1.xsd main2.xsd
Writing file 'shared_main1_main2.cs'.

When I try the same thing with XmlSchemaClassGenerator, I get a variety of exceptions. At first I thought it was a problem with two xsd files importing the same shared file, but then I tried it with just one of the main files. The exception I get depends on which file I specify first:

>XmlSchemaClassGenerator.Console.exe shared.xsd main1.xsd
Unhandled Exception: System.Exception: Namespace main1 not provided through map or generator.
   at XmlSchemaClassGenerator.Generator.BuildNamespace(Uri source, String xmlNamespace)
   at XmlSchemaClassGenerator.Generator.CreateNamespaceModel(Uri source, XmlQualifiedName qualifiedName)
   at XmlSchemaClassGenerator.Generator.CreateTypeModel(Uri source, XmlSchemaAnnotated type, XmlQualifiedName qualifiedName)
   at XmlSchemaClassGenerator.Generator.BuildModel()
   at XmlSchemaClassGenerator.Generator.Generate(IEnumerable`1 files)
   at XmlSchemaClassGenerator.Console.Program.Main(String[] args)


>XmlSchemaClassGenerator.Console.exe main1.xsd shared.xsd
Unhandled Exception: System.Xml.Schema.XmlSchemaException: The complexType 'Shared:sharedType' has already been declared.
   at System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e)
   at System.Xml.Schema.BaseProcessor.AddToTable(XmlSchemaObjectTable table, XmlQualifiedName qname, XmlSchemaObject item)
   at System.Xml.Schema.Compiler.Prepare(XmlSchema schema, Boolean cleanup)
   at System.Xml.Schema.XmlSchemaSet.Compile()
   at XmlSchemaClassGenerator.Generator.Generate(IEnumerable`1 files)
   at XmlSchemaClassGenerator.Console.Program.Main(String[] args)

shared.xsd
main1.xsd
main2.xsd

@mganss
Copy link
Owner

mganss commented Feb 22, 2018

The shared file must not be specified on the command line and you must specify identifiers for the main1 and main2 namespaces:

XmlSchemaClassGenerator.Console.exe main?.xsd -n main1=Main1 -n main2=Main2

The fact that you have to explicitly specify the namespace identifiers is due to a shortcoming in the code that autogenerates namespace identifiers AFAICT. I'll fix this shortly.

@mganss mganss closed this as completed in 738e333 Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants