Skip to content

Codegen localElementDictionary type incorrect for inherited properties on anonymous type #83

@john-surcombe

Description

@john-surcombe

When generating code for the following minimal schema: schema.xsd.xml

The output has missing type information (typeof(void)) on the localElementDictionary for the type Root.ElementLocalType:

private static void BuildElementDictionary()
{
    localElementDictionary.Add(BaseTypeMemberXName, typeof(void));
}

The causes problems with unnecessary (and potentially invalid) xsi:type attributes being generated for these members during XML serialization. The issue seems to specifically affect anonymous types which extend a named base type that has a complexType element.

As a workaround I am using a partial class at runtime to fix the incorrect localElementDictionaries.

The issue is in XsdToTypesConverter.BuildPropertyForElement, which only adds anonymous types to the localSymbolTable if they did not come from the base type. Then the type info doesn't get populated when the anonymous types are enumerated later (in LocalSymbolTable.GetAnonymousTypes).

This patch (based on master) addresses the issue by adding all anonymous types but skipping ones from the base type in the later enumeration:

0001-Codegen-localElementDictionary-type-incorrect-for-in.patch

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