Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 584951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:57:06+00:00 2026-05-13T14:57:06+00:00

I am using the .NET XSD.EXE importer to generate C# classes from a collection

  • 0

I am using the .NET XSD.EXE importer to generate C# classes from a collection of XSD files. When I tried to serialize one of the classes to XML it failed (InvalidOperationException), and when I dug into it I discovered it one of the created classes appears to be wrong.

Here is the pertinent XSD code:

<xsd:complexType name="SuccessType">
    <xsd:annotation>
        <xsd:documentation>Indicates in a response message that a request was successfully processed.</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
        <xsd:element ref="Warnings" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>
<!-- .. snip .. -->
<xsd:element name="Warnings" type="WarningsType">
    <xsd:annotation>
        <xsd:documentation>The processing status of a business message and any related warnings or informational messages.</xsd:documentation>
    </xsd:annotation>
</xsd:element>
<!-- .. snip .. -->
<xsd:complexType name="WarningsType">
    <xsd:annotation>
        <xsd:documentation>A collection of warnings generated by the successful processing of a business message.</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
        <xsd:element ref="Warning" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>
<!-- .. snip .. -->
<xsd:element name="Warning" type="WarningType">
    <xsd:annotation>
        <xsd:documentation>Defines details of a warning that occurred during message processing.</xsd:documentation>
    </xsd:annotation>
</xsd:element>
<!-- .. snip .. -->
<xsd:complexType name="WarningType">
    <xsd:annotation>
        <xsd:documentation>Defines details of a warning that occurred during message processing.</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
        <xsd:element ref="WarningCategory"/>
        <xsd:element ref="WarningCode"/>
        <xsd:element ref="WarningShortMessage"/>
        <xsd:element ref="WarningMessage"/>
    </xsd:sequence>
</xsd:complexType>

And here is the C# code generated from it:

public partial class SuccessType
{

    private WarningType[][] warningsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("Warning", typeof(WarningType), IsNullable = false)]
    public WarningType[][] Warnings
    {
        get
        {
            return this.warningsField;
        }
        set
        {
            this.warningsField = value;
        }
    }
}

It made Warnings an array of an array of WarningType. When I attempt to serialize that to XML I get an InvalidOperationException exception:

  • Unable to generate a temporary class (result=1).
  • error CS0030: Cannot convert type ‘WarningType[]’ to ‘WarningType’
  • error CS0030: Cannot convert type ‘WarningType[]’ to ‘WarningType’
  • error CS0029: Cannot implicitly convert type ‘WarningType’ to ‘WarningType[]’
  • error CS0029: Cannot implicitly convert type ‘WarningType’ to ‘WarningType[]’

But if I change the generated code from WarningType[][] to WarningType[] then it serializes fine.

Short of editing the generated C# class whenever I regenerate this (which hopefully will be less frequently going forward), is there any other solution? Is this a bug in xsd.exe or is the XSD file incorrect? Maybe there is a problem in the XmlSerializer?

What I want is C# code that correctly serializes to XML that validates against the XSD. Right now the jagged array seems to be wrong because if I remove it then it generates the XML.

I am using Visual Studio 2008.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:57:07+00:00Added an answer on May 13, 2026 at 2:57 pm

    There are bugs in the xsd.exe tool. I don’t remember this particular one, but I do remember finding problems with jagged arrays, and it’s possible this remains a bug. if you’re willing, you could use the XsdObjbectGen tool, also from Microsoft, but released independently and out-of-band from the .NET SDK.

    One thing you could do is go the reverse direction: write the C# code, then generate the schema with xsd.exe, and see what is different. It’s possible xsd.exe wants the schema to look a particular way, in order to correctly generate correct code for jagged arrays.


    Actually, upon re-reading your question, you never said what you really wanted. Do you want SuccessType to contain an array-of-arrays, or not?

    And is it WarningsType or WarningType? There’s some disagreement between the code snips you provided.


    Assuming you wanted the array-of-arrays, I wrote this C# code:

    public class WarningType
    {
        public String oof;
    }
    
    
    public partial class SuccessType
    {
        private WarningType[][] warningsField;
    
        /// <remarks/>
        [System.Xml.Serialization.XmlArrayItemAttribute("Warning", typeof(WarningType[]), IsNullable = false)]
        public WarningType[][] Warnings
        {
            get
            {
                return this.warningsField;
            }
            set
            {
                this.warningsField = value;
            }
        }
    }
    

    … then compiled it into a DLL. Then I ran xsd.exe on that DLL, and generated this XSD:

    <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="WarningType" nillable="true" type="WarningType" />
      <xs:complexType name="WarningType">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="1" name="oof" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="SuccessType" nillable="true" type="SuccessType" />
      <xs:complexType name="SuccessType">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="1" name="Warnings" type="ArrayOfArrayOfWarningType" />
        </xs:sequence>
      </xs:complexType>
      <xs:complexType name="ArrayOfArrayOfWarningType">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="unbounded" name="Warning" type="ArrayOfWarningType" />
        </xs:sequence>
      </xs:complexType>
      <xs:complexType name="ArrayOfWarningType">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="unbounded" name="WarningType" nillable="true" type="WarningType" />
        </xs:sequence>
      </xs:complexType>
    </xs:schema>
    

    …and it round-trips. If I then run xsd.exe on that schema, I get a type that wraps an array-of-arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are the options to generate .NET 4.0 c# classes (entities) from an xsd
I have defined schema for xml in file packetTemplate.xsd.Using ms tool xsd.exe i have
Converting WSDL to C# classes using microsoft net wsdl.exe tool but the tool is
I want to generate java code from xsd using JAXB 2.1 XJC. I have
I auto-generated some classes using xsd.exe for a project I am working on. I
I want to create a ASP.NET user control from an XML using XSLT. Currently
Using .Net and Oracle 11g - I've been returning dataTables from a procedure inside
I'm using .NET framework (tried 3.5 & 4.0) to load a .TIFF file and
I'm using JAXB 2.1.10 from Sun's JDK 1.6.0_18: D:\apps\jdk160_18\bin>xjc.exe -version xjc version JAXB 2.1.10
Background Converting from using .Net Remoting to WCF. Most of the methods on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.