PascalCase and XmlArrayItemAttribute


Thanks for the PascalCase feature in 3.5 beta. It's really useful.
I found a problem when using PascalCase with XmlArray. Given the following XML:
And the following generated code (slighly changed):
public partial class Message
    private MessageActionseg actionsegField;
    private List<MessageListrecord> alternatelistsegField;
    public MessageActionseg Actionseg
            if ((this.actionsegField == null))
                this.actionsegField = new MessageActionseg();
            return this.actionsegField;
            this.actionsegField = value;
    [System.Xml.Serialization.XmlArrayItemAttribute("listrecord", IsNullable = false)]
    public List<MessageListrecord> Alternatelistseg
            if ((this.alternatelistsegField == null))
                this.alternatelistsegField = new List<MessageListrecord>();
            return this.alternatelistsegField;
            this.alternatelistsegField = value;
Xsd2Code will try to mix up XmlElementAttribute and XmlArrayItemAttribute which will fall into the following exception:
  • XmlElement, XmlText, and XmlAnyElement cannot be used in conjunction with XmlAttribute, XmlAnyAttribute, XmlArray, or XmlArrayItem.
    The right attributes should be:
    [System.Xml.Serialization.XmlArrayItemAttribute("listrecord", IsNullable = false)]
    Thanks for your help. Thanks for this tool.


scotthill1980 wrote Sep 28, 2012 at 2:45 PM

Thanks for the new PascalCase feature - I've been after this for some time ;o)

I'm seeing the same issue with the attributes mentioned above :o(

In addition, when using PascalCase I think you need to add the [XmlRoot()] attribute to the class and define the non pascal case element name. Without this, the classes do not de serialise correctly when used directly.

e.g. [XmlRoot("camelCaseName")]

Otherwise a great tool. Thanks for your hard work.


jayjoe wrote Jan 25, 2013 at 1:51 PM

Hello, i would be very thankfull, if someone could correct the error above.
Therefore i'll try to explain it a bit more.

At the Moment it may be produced code like this:
[System.Xml.Serialization.XmlArrayItemAttribute("bar", IsNullable = false)]
        public List<SendemitschnittType> Foo
When de-/serializing an xml it will throw errors because XmlElementAttribute and XmlArrayItemAttribute may not be used side-by-side, correct would be to have XmlArrayAttribute instead of XmlElementAttribute.

this failure will only happen when PascalCase PropertyName Generation is activated

xsd code to produce error
      <xs:element name="foo">
            <xs:element maxOccurs="unbounded" name="bar" type="shortString" />

wrote Jan 25, 2013 at 1:53 PM

wrote Feb 22, 2013 at 1:18 AM

wrote Mar 6, 2013 at 1:54 PM

wrote Jun 24, 2013 at 3:00 PM

wrote Oct 16, 2013 at 8:13 AM