Skip to content

Handle only distinct ambiguous type names #559

@abrasat

Description

@abrasat

In an application where the XmlSchemaSet contains several xml schema files (the main schema file references other xml schema files) I get a type name ("AnyType") twice in the list with ambiguous types. This leads to an exception in the GetQualifiedName() function, as schemaType is null.
Please modify the AddXmlRootAttributeToAmbiguousTypes() function in ModelBuilder.cs from:

    private void AddXmlRootAttributeToAmbiguousTypes()
    {
        var ambiguousTypes = Types.Values.Where(t => t.RootElementName == null && !t.IsAbstractRoot && t is not InterfaceModel).GroupBy(t => t.Name);
        foreach (var ambiguousTypeGroup in ambiguousTypes)
        {
            var types = ambiguousTypeGroup.ToList();
            if (types.Count == 1)
            {
                continue;
            }
            foreach (var typeModel in types)
                typeModel.RootElementName = typeModel.GetQualifiedName();
        }
    }

to:

    private void AddXmlRootAttributeToAmbiguousTypes()
    {
        var ambiguousTypes = Types.Values.Where(t => t.RootElementName == null && !t.IsAbstractRoot && t is not InterfaceModel).GroupBy(t => t.Name);
        foreach (var ambiguousTypeGroup in ambiguousTypes)
        {
            var types = ambiguousTypeGroup.DistinctBy(x => x.Name).ToList();
            if (types.Count == 1)
            {
                continue;
            }
            foreach (var typeModel in types)
                typeModel.RootElementName = typeModel.GetQualifiedName();
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions