0

I have used the xsd.exe program to create a class hierarchy for a xsd file. I am successfully able to deserialize a xml file and read values from it in C#. However when i register the library and am trying to read array values from VBScript it fails. I get Wrong number of arguments or invalid property assignment error. I am however able to read the values of simple properties.

Here is my class hierarchy

using System.Xml.Serialization;

public partial class AppEntryDefinition {

    private ProductDefinition productDefinitionField;

    private ViewSection[] viewDefinitionField;

    public ProductDefinition productDefinition {
        get {
            return this.productDefinitionField;
        }
        set {
            this.productDefinitionField = value;
        }
    }

/// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("viewSection", IsNullable=false)]
    public ViewSection[] viewDefinition {
        get {
            return this.viewDefinitionField;
        }
        set {
            this.viewDefinitionField = value;
        }
    }
}

public partial class ProductDefinition {

    private int kindCodeField;

    private string productCodeField;

    private string productTitleField;

    private string adminSystemField;

    private string vapCodeField;

    private Features featuresField;

    private RuleSet[] ruleSetField;

    /// <remarks/>
    public int kindCode {
        get {
            return this.kindCodeField;
        }
        set {
            this.kindCodeField = value;
        }
    }

    /// <remarks/>
    public string productCode {
        get {
            return this.productCodeField;
        }
        set {
            this.productCodeField = value;
        }
    }

    /// <remarks/>
    public string productTitle {
        get {
            return this.productTitleField;
        }
        set {
            this.productTitleField = value;
        }
    }

    /// <remarks/>
    public string adminSystem {
        get {
            return this.adminSystemField;
        }
        set {
            this.adminSystemField = value;
        }
    }

    /// <remarks/>
    public string vapCode {
        get {
            return this.vapCodeField;
        }
        set {
            this.vapCodeField = value;
        }
    }

    /// <remarks/>
    public Features features {
        get {
            return this.featuresField;
        }
        set {
            this.featuresField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("ruleSet")]
    public RuleSet[] ruleSet {      
        get {
            return this.ruleSetField;
        }
        set {
            this.ruleSetField = value;
        }
    }
} 

public partial class RuleSet {

    private Rule[] ruleField;

    private string phaseField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("rule")]
    public Rule[] rule {
        get {
            return this.ruleField;
        }
        set {
            this.ruleField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string phase {
        get {
            return this.phaseField;
        }
        set {
            this.phaseField = value;
        }
    }
} 

public partial class Rule {

    private Case[] caseField;

    private string nameField;

    private string typeField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("case")]
    public Case[] @case {
        get {
            return this.caseField;
        }
        set {
            this.caseField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string type {
        get {
            return this.typeField;
        }
        set {
            this.typeField = value;
        }
    }
}

Here is my code which deserializes my xml to objects

namespace CustomUtilities
{
    public class XmlSerializer
    {
        public AppEntryDefinition Deserialize(String xmlPath)
        {

            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(AppEntryDefinition));
            AppEntryDefinition aed = null;
            aed = (AppEntryDefinition)serializer.Deserialize(new System.IO.StreamReader(xmlPath));
            return aed;
        }
    }
}

Here is my vbscript code

Dim obj, objAppEntry
Set obj = CreateObject("CustomUtilities.XmlSerializer")
Set objAppEntry = obj.Deserialize("C:\Users\xx\Desktop\schema\xx.xml")
Set xxx = objAppEntry.productDefinition.ruleSet
2
  • Arrays may not cross the VBScript/COM <-> .NET interop layer easily, so that may be expected. Please post a specific piece of code so we may provide further help. Commented Feb 4, 2014 at 16:26
  • @SimonMourier Please see sample code above Commented Feb 4, 2014 at 17:21

1 Answer 1

1

Yes, these arrays will not get through from NET to VBScript as they are not COM automation compatible.

What you can do, though, is create a partial class with the same name as the initial one, duplicate the array properties, give them another name, and declare them as a type that can be used in automation (and recompile the whole thing). You could create a custom type (it's necessary if yuo don't want to duplicate the values), but the easiest way to do it is to reuse the "old" ArrayList class. It's marked as COM visible and it can be used easily from a script language.

So here is a sample partial add-on:

public partial class ProductDefinition
{
    [XmlIgnore]
    public ArrayList ruleSetArrayList
    {
        get
        {
            return new ArrayList(ruleSet);
        }
    }     
}

And the script that uses it:

Set xxx = objAppEntry.productDefinition.ruleSetArrayList
for each item in xxx
    WScript.echo item.phase
next
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.