Skip to content
New issue

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

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

Already on GitHub? # to your account

Invalid generated code - interface does not return matching type #305

Closed
dallyh opened this issue Feb 4, 2022 · 1 comment
Closed

Invalid generated code - interface does not return matching type #305

dallyh opened this issue Feb 4, 2022 · 1 comment

Comments

@dallyh
Copy link

dallyh commented Feb 4, 2022

Hi, while generating classes from this XSD: http://www.isdoc.cz/6.0/xsd/isdoc-invoice-6.0.1.xsd with interface option enabled, an interface called ISignature gets created:

public partial interface ISignature
    {

        System.Xml.XmlElement Any
        {
            get;
            set;
        }
    }

This interface gets referenced in the Invoice class:

public partial class Invoice : ISignature

This is all fine, however this error occurs:
'Invoice' does not implement interface member 'ISignature.Any'. 'Invoice.Any' cannot implement 'ISignature.Any' because it does not have the matching return type of 'XmlElement'.

And the "Any" element of Invoice class:

[System.Xml.Serialization.XmlAnyElementAttribute()]
        public System.Collections.ObjectModel.Collection<System.Xml.XmlElement> Any
        {
            get
            {
                return this._any;
            }
            private set
            {
                this._any = value;
            }
        }

Signature is a group in the XSD and its referenced in the Invoice element.

I have generated the code without interface generation and it works fine. However, I just wanted to ask if I'm doing something wrong, or if this is one of the exceptions where interface generation doesn't work.

@mganss mganss closed this as completed in 7fb5352 Feb 7, 2022
@mganss
Copy link
Owner

mganss commented Feb 7, 2022

This occurred if an element had maxOccurs=1 in the group definition, and maxOccurs>1 in the referencing element's definition. I've added code in 2.0.646 to promote the interface property to a collection in these cases (along with the corresponding properties in all other implementing classes).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants