3
Vote

xs:choice nested in xs:sequence throws exception

description

If a xs:choice is nested in a xs:sequence running the generated code throws an exception like:
Type of choice identifier 'Items1ElementName' is inconsistent with type of 'Items1'. Please use array of System.Collections.Generic.List ...
This error was raised and described in http://xsd2code.codeplex.com/discussions/48138 and http://xsd2code.codeplex.com/discussions/224616 but no real solution was provided in any of the discussion threads as replacing the List by an array causes another error (at least in NET 4): Unable to generate a temporary class (result=1). error CS1061: 'System.Collections.Generic.List<namespace.FlexPropType>' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'System.Collections.Generic.List<namespace.FlexPropType>' could be found (are you missing a using directive or an assembly reference?) (this error is described at http://stackoverflow.com/questions/6866301)
 
So maybe a modification in the Xsd2Code code template could solve this issue.

file attachments

comments

manchuwook wrote May 15, 2012 at 6:23 PM

This error gets raised whenever trying to serialise an object:
        try {

            Note n = new Note() {
                Type = new Notetype() {
                    Value = Notetypevalue.whole
                }
            };

            n.ItemsElementName.Add(ItemsChoiceType1.pitch);
            n.Items.Add(new Pitch() {
                Step = Step.A,
                Octave = "4"
            });

            n.ItemsElementName.Add(ItemsChoiceType1.duration);
            n.Items.Add("4");

            Debug.WriteLine(n.Serialize());

        } catch (Exception) {

            throw;
        }

mightymuke wrote Sep 14, 2012 at 11:06 AM

Attached a patch for revision 95554. Its a bit rubbish, but works for me.

Fetrovsky wrote Oct 1, 2012 at 12:38 AM

Where can I download the library or installer with this patch?

mightymuke wrote Oct 1, 2012 at 3:23 AM

I'm afraid you can't as it hasn't been applied to the source yet. If you need it urgently then your best bet is to download the current source and build it yourself. Based on the status of other patches, this may also be your only option.

Note that I've only tested it in my application, so while it get the WOMM (Works On My Machine) stamp, it may not work for you.