tags:

views:

324

answers:

2

Hello,

I am trying to generate C# code from an XML schema with xsd.exe with Visual Studio RC1 (version 10.0.30128.1) but get the follwoing error:

C:\Development>xsd CR2008Schema.xsd /classes Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30128.1] Copyright (C) Microsoft Corporation. All rights reser

Process is terminated due to StackOverflowException.

The xsd is http://www.businessobjects.com/products/xml/CR2008Schema.xsd

Any help appreciated.

Thanks,

Staffan

+2  A: 

This is probably happening because Group defines a collection of Group:

<!--    Group   -->
<xsd:complexType name="Group">
  <xsd:sequence>
    <xsd:element name="GroupHeader" type="HeaderFooter" minOccurs="0"/>
      <xsd:choice>
        <xsd:element name="Details" type="Details" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element name="Group" type="Group" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:choice>
    <xsd:element name="GroupFooter" type="HeaderFooter" minOccurs="0"/>
  </xsd:sequence>
  <xsd:attribute name="Level" type="xsd:integer" use="required"/>
</xsd:complexType>

xsd.exe is getting into an infinite loop...

Oded
+1  A: 

Further to Oded's answer there is a similar but more comples loop in the CrystalReport type. The Details element of type Details contains a SubReport element that is of type Subreport, that inherits from CrystalReport, which contains a Details element of type Details etc.

Ben Robinson
Thanks a lot for the quick response! That makes sense. Does it mean that there is no way to generate the correct C# code? It does work when I remove Group and Subreport and should this be sufficient for me right now but I am curious...
Staffan
You could manually create the classes, but you would could encounter problems serialising them to XML as there is a potential for a circular reference. e.g. Object A of type group has a Group property of type group that references object B. If object B's group property referenced object A you would then have a circular reference. You could never serialise this as it would go on forever.
Ben Robinson