XmlSchemaClassGenerator icon indicating copy to clipboard operation
XmlSchemaClassGenerator copied to clipboard

Duplicate name between class and namespace.

Open devl-up opened this issue 1 year ago • 1 comments

When generating the hierarchy of my XSD, there seem to be a clash between a classname and a namespace.

This class get's generated

namespace Be.Fr.Cbso.Dict.Dom
{
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Diagnostics;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    
    
    [GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1162.0")]
    [SerializableAttribute()]
    [XmlTypeAttribute("aln", Namespace="http://www.nbb.be/be/fr/cbso/dict/dom/")]
    [DebuggerStepThroughAttribute()]
    [DesignerCategoryAttribute("code")]
    [XmlRootAttribute("aln", Namespace="http://www.nbb.be/be/fr/cbso/dict/dom/")]
    public partial class Aln : Instance.StringItemType
    {
    }
}

Under the Be.Fr.Cbso.Dict.Dom namespace with name Aln

Problem is there is also a namespace with the exact same name

Be.Fr.Cbso.Dict.Dom.Aln

namespace Be.Fr.Cbso.Dict.Dom.Aln
{
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Diagnostics;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    
    
    [GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1162.0")]
    [SerializableAttribute()]
    [XmlTypeAttribute("m0", Namespace="http://www.nbb.be/be/fr/cbso/dict/dom/aln")]
    [DebuggerStepThroughAttribute()]
    [DesignerCategoryAttribute("code")]
    [XmlRootAttribute("m0", Namespace="http://www.nbb.be/be/fr/cbso/dict/dom/aln")]
    public partial class M0_2 : Dtr.Type.DomainItemType
    {
    }
}

Which gives me a compilation error. Is this a problem with how the XSD is structured or a bug ? (I'm not the maintainer / owner of the XSD, but it's one generated by our national bank, and used by many other companies)

devl-up avatar Sep 13 '24 11:09 devl-up

Try substituting the Aln class name for something else using the --tns option. See https://github.com/mganss/XmlSchemaClassGenerator?tab=readme-ov-file#substituting-generated-c-type-and-member-names

mganss avatar Sep 13 '24 11:09 mganss