xsd2code byte[] array init

Feb 25, 2010 at 2:03 PM

xsd2exe generates xml attribute of type base64 like:

<font size="2" color="#0000ff"><font size="2" color="#0000ff">


</font></font><font size="2" color="#0000ff">



.binaryField = new byte[]()


This will not compile

Can this bug be fixed easily?




this is my first post - please take it easy :)

Feb 25, 2010 at 3:55 PM

would you believe that I have the exact same problem? I'm just looking at this today and saw your post.

It's causing my code to fail at building. Again, the line is

[System.Xml.Serialization.XmlAttributeAttribute(DataType = "base64Binary")]
        public byte[] integrityCheck
            get {
                if ((this.integrityCheckField == null)) {
                    this.integrityCheckField = new byte[]();
                return this.integrityCheckField;
                this.integrityCheckField = value;

I set the array to some arbitary value, but alas I get a stack overflow.

Feb 25, 2010 at 3:59 PM

So I tried this

this.integrityCheckField = new List<byte>();

Seems to compile. You could try:

.binaryField = new List<byte>();

Mar 1, 2010 at 3:48 PM

I cannot convert it to List<byte> as it would break number of projects. Also a problem is not solved by hiding it. Anotehr problem with this code generator is that it's not generating comments for attributes or even classes which are defined as a complex type.


If I get a chance I'll look at the source code to see where the issues are coming from.



Mar 8, 2010 at 9:08 PM

Can you post a litte XSD sample.




Mar 9, 2010 at 9:56 AM

Here's a cut down version of my schema. 


  <xs:complexType name="BinaryCapture">
      <xs:documentation>A image capture.</xs:documentation>
      <xs:extension base="CaptureBase">
        <xs:attribute name="BinaryImage" type="xs:base64Binary">
            <xs:documentation>Gets or sets the image data.</xs:documentation>
        <xs:attribute name="BinaryDataType" default="None" type="mstns:BinaryDataTypes">
            <xs:documentation>Gets or sets the type of the image.</xs:documentation>
        <!--<xs:attribute name="BinaryImageFileName" type="xs:string">
            <xs:documentation>Gets or sets the image file name.</xs:documentation>

  <xs:element name="Captures">
        <xs:element name="BinaryCaptures" type="mstns:BinaryCapture" maxOccurs="unbounded" minOccurs="1">
            <xs:documentation>List of binary captures.</xs:documentation>

Jun 7, 2010 at 6:15 PM
Edited Jun 7, 2010 at 6:16 PM

I have similar issue.

XSD snippet:

  <simpleType name="colorType">
        ffffffff: opaque white
        ff000000: opaque black
    <restriction base="hexBinary">
      <length value="4"/>

Later, an element declared thus:
  <element name="bgColor" type="kml:colorType" default="ffffffff"/>

Gets converted to: 
		private byte[] bgColorField;
            this.bgColorField = new byte[]();

Instead, it should be declared as byte[4], per the colorType definition.
Jun 7, 2010 at 7:05 PM

I reported this as issue 7210.