mganss / XmlSchemaClassGenerator

Generate C# classes from XML Schema files
Apache License 2.0
603 stars 180 forks source link

Dictionary Key exception when using `-netcore` #498

Closed Yazwh0 closed 7 months ago

Yazwh0 commented 7 months ago

While trying to generate code based on the attached .xsd, the application fails if -netcore is specified when -n is also used.

It works otherwise. (So -netcore but no namespace name is fine.)

c:\test>generator\XmlSchemaClassGenerator.Console.exe -netcore head.001.001.01_ESMA_restricted.xsd

c:\test>generator\XmlSchemaClassGenerator.Console.exe -netcore -n foo head.001.001.01_ESMA_restricted.xsd

Unhandled Exception: System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at XmlSchemaClassGenerator.EnumerableExtensions.ToNamespaceProvider(IEnumerable`1 items, GenerateNamespaceDelegate generate)
   at XmlSchemaClassGenerator.Console.Program.Main(String[] args)

head.001.001.01_ESMA_restricted.xsd.zip

mganss commented 7 months ago

You need to specify the --netCore option using two dashes, i.e. either --netCore or --nc. Otherwise it will be interpreted as the -n option, specifying etcore as the C# namespace for the empty XML namespace which you have already mapped to the foo C# namespace.