Creation of C# Classes with the Wix.xsd

Jan 12, 2009 at 4:32 PM

I hve 2 issues.

Part 1:
I am trying to use the generator to create C# classes from the Wix 3.0 "wix.xsd". While the creation of the classes occurs I am getting some unusual errors.

When I try and compile I get the error:
    Error 77 'Carlos.YesNoType' does not contain a definition for 'IO' and no extension method 'IO' accepting a first argument of type 'Carlos.YesNoType' could be found (are you missing a using directive or an assembly reference?)

And the companion line in the source is this one:
        memoryStream.Seek(0, System.IO.SeekOrigin.Begin); Line 13937
This is due to the fact that the definition of:

    public YesNoType System - Line 13875

Is scoping the "System.IO" call.  Is ther a way to fix this formally? Is there something wrong in the way the Wix.xsd is defined that is causing this?

Part 2:

If I fix the above issue by changing the 2 places that "public YesNoType System" is defined to "public YesNoType SystemType" then I get a successful compile.

When I run the following code:

Wix myWixObj = null;
    Exception e = null;
Wix.LoadFromFile(@"C:\Product_Trial1.wxs", out myWixObj, out e);

I get an exception and the folloing error:
    "There was an error reflecting property 'Items'."

The file (@"C:\Product_Trial1.wxs" is a "correct" xix file; I can compile successfully with the Wix compiler.

Any suggestions or hints are much appreciated. If other information is needed I will supply it.



Jan 14, 2009 at 10:35 AM
The problem is that xsd2code or xsd.exe doesn't support this sucture :

            <xs:choice minOccurs="0">
                    <xs:choice minOccurs="0">

                        <xs:element ref="Product"/>
                        <xs:element ref="Module"/>
                        <xs:element ref="Patch"/>
                    <xs:element ref="Fragment" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="PatchCreation"/>

complexType -> choice -> sequence -> choice, generate List<object> (with <<item>> property name).
If you change all by complexType -> sequence it will generate List<Product> (LoadFromFile work fine.)

        <xs:element ref="Product" />
        <xs:element ref="Module" />
        <xs:element ref="Patch" />
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="Fragment" />
        <xs:element ref="PatchCreation" />

If you don't change wix.xsd, i don't have any solution.
But i looked into source code of wix and i found a interesting tool called xsdGen.
Did you try it ?
Jan 14, 2009 at 12:53 PM

First, thank you very much for answering my post.

What you state makes sense to me. My take away from your description is that I would have to change the "wix.xsd" to have the tool generate the appropriate collection type, in this case List<item>, so that "LoadFromFile would work as expected. I hesitate to make such a change since I would be changing a "standard" xsd defintion. However, I did not know about the Tool from the Wix SDK called "xsdGen". I will look into this tool - I would prefer to use it rather than change the xsd definition.

Is the tool that you mention part of the "Wix Tool Set" from Source Forge or from Microsoft Dev Studio 2008? I will look in my Wix 3.0 beta installation for the tool.

Thanks again for you help

Jan 14, 2009 at 1:38 PM
Edited Jan 14, 2009 at 1:58 PM
I have download it from sourceforge.
I can tell you that XsdGen work fine on wix.xsd.
You can see part of generated code (whith XsdGen Choice and sequence are supported)

    [GeneratedCode("xsdGenConsole", "")]
    public class Wix : IParentElement, ICreateChildren, ISchemaElement, ISetAttributes
        private ElementCollection children;
        private string requiredVersionField;
        private bool requiredVersionFieldSet;
        private ISchemaElement parentElement;
        public Wix()
            ElementCollection childCollection0 = new ElementCollection(ElementCollection.CollectionType.Choice);
            ElementCollection childCollection1 = new ElementCollection(ElementCollection.CollectionType.Sequence);
            ElementCollection childCollection2 = new ElementCollection(ElementCollection.CollectionType.Choice);
            childCollection2.AddItem(new ElementCollection.ChoiceItem(typeof(Product)));
            childCollection2.AddItem(new ElementCollection.ChoiceItem(typeof(Module)));
            childCollection2.AddItem(new ElementCollection.ChoiceItem(typeof(Patch)));

            childCollection1.AddItem(new ElementCollection.SequenceItem(typeof(Fragment)));
            childCollection0.AddItem(new ElementCollection.ChoiceItem(typeof(PatchCreation)));
            this.children = childCollection0;

You can download just xsdgen (source and binary) at this adress :

Aug 30, 2009 at 12:01 PM
Edited Aug 30, 2009 at 12:01 PM

I can not find xsdGen tool.

The link you provided is not working and its not under my wix installation.

Please help, since I am facing exactly the same problem.