Creation of C# Classes with the Wix.xsd

Jan 12, 2009 at 3: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:

    [System.Xml.Serialization.
XmlAttributeAttribute()]
    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:

    Carlos.
Wix myWixObj = null;
    Exception e = null;
    Carlos.
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.

Regards,
CNazman

 

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

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

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

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:complexType>
      <xs:sequence>
        <xs:element ref="Product" />
        <xs:element ref="Module" />
        <xs:element ref="Patch" />
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="Fragment" />
        <xs:element ref="PatchCreation" />
      </xs:sequence>
    </xs:complexType>

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 ?
Pascal.
Jan 14, 2009 at 11:53 AM
Pascal,

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

Regards,
CNazman
Coordinator
Jan 14, 2009 at 12:38 PM
Edited Jan 14, 2009 at 12: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", "1.0.0.0")]
    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.AddCollection(childCollection2);
            childCollection1.AddItem(new ElementCollection.SequenceItem(typeof(Fragment)));
            childCollection0.AddCollection(childCollection1);
            childCollection0.AddItem(new ElementCollection.ChoiceItem(typeof(PatchCreation)));
            this.children = childCollection0;
        }

You can download just xsdgen (source and binary) at this adress :
http://www.myxaml.fr/xsdgenconsole.zip

Pascal.
Aug 30, 2009 at 11:01 AM
Edited Aug 30, 2009 at 11:01 AM

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.