Microsoft KB Archive/815106

= BUG: Xsd.exe tool generates an incorrect class when the XML Schema has a group element in a choice element =

Article ID: 815106

Article Last Modified on 9/15/2005

-

APPLIES TO


 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft .NET Framework 1.0
 * Microsoft .NET Framework 1.1

-





Beta Information
This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about how to obtain support for a Beta release, see the documentation that is included with the Beta product files, or check the Web location from which you downloaded the release.



SYMPTOMS
You use a group element in a choice element in an XML Schema, and then use the XML Schema Definition Tool (Xsd.exe), to generate a Visual C# .NET class or a Visual Basic .NET class. When you generate the class, the code for the group and choice elements is not present in the generated class.



WORKAROUND
To work around this problem, do not use the group element in the choice element. Instead of using a group element in a choice element, add all the elements of the group element to the choice element. For example, for the schema that is described in step 5 of the &quot;More Information&quot; section, instead of the following:  use the following in step 5:   



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click File. In the New File dialog box, click General under Categories, click XML Schema under Templates, and then click Open.</li> Right-click XMLSchema1, and then click View XML Source.</li>  In the XML pane, replace the existing code with the following code: <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?> <s:schema xmlns:s=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:s0=&quot;http://www.goffinf.co.uk/webservices&quot; targetNamespace=&quot;http://www.goffinf.co.uk/webservices&quot;> <s:element name=&quot;BadChoice&quot;> <s:complexType> <s:sequence> <s:element name=&quot;Forename&quot; type=&quot;s:string&quot; /> <s:element name=&quot;Surname&quot; type=&quot;s:string&quot; /> <s:choice> <s:element name=&quot;StaffNo&quot; type=&quot;s:string&quot; /> <s:group ref=&quot;s0:PersonalStats&quot; /> </s:choice> </s:sequence> </s:complexType> </s:element> <s:group name=&quot;PersonalStats&quot;> <s:sequence> <s:element name=&quot;Age&quot; type=&quot;s:positiveInteger&quot; /> <s:element name=&quot;Height&quot; type=&quot;s:positiveInteger&quot; /> <s:element name=&quot;Weight&quot; type=&quot;s:positiveInteger&quot; /> </s:sequence> </s:group> </s:schema> </li> On the File menu, click Save XMLSchema1, and then save the schema file as C:\XMLSchema1.xsd .</li> Open a Visual Studio .NET command prompt.</li>  Type the following command, and then press ENTER to generate code:

Visual C# .NET Code: xsd /c /l:cs /o:c:\ c:\XMLSchema1.xsd

Visual Basic .NET Code: xsd /c /l:vb /o:c:\ c:\XMLSchema1.xsd </li></ol>

In the generated class file, you may not find entries for the group element. For example, there is no entry for Age or Height or Weight.

<div class="references_section">