Microsoft KB Archive/818218

= You receive &quot;'columnName' is already declared&quot; errors when you build a Visual Basic .NET or Visual Basic 2005 project =

Article ID: 818218

Article Last Modified on 11/22/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



SYMPTOMS
You have an XML schema with elements that have the same name in different cases (for example, MYELMENT and MyElement). When you generate the DataSet for the XML schema in Visual Basic .NET or Visual Basic 2005, and you try to build the application that consumes the DataSet, you receive the following errors:

'columnMYELEMENT' is already declared as 'Private Dim columnMYELEMENT As System.Data.DataColumn' in this class.

Property 'MYELEMENT' has multiple definitions with the same signatures.

Parameter already declared with name 'MyElement'.

Property 'MYELEMENTColumn' has multiple definitions with the same signatures.



CAUSE
When you generate a DataSet from an XML schema, an XMLSchemaName.vb file is also created with the DataSet schema. In the Visual Basic .NET or Visual Basic 2005 file, the elements of the XML schema are declared as DataColumn. Therefore, there are two declare statements (one for each element). Because Visual Basic .NET or Visual Basic 2005 is case-insensitive, it cannot distinguish between the two declare statements that only differ by case. Therefore, you receive errors when you build the project.



RESOLUTION
To resolve the problem, change the name of the element in the XML schema. To do this, follow these steps:
 * 1) Right-click Schema designer, and then click View XML Source.
 * 2) Replace the element name MyElement with MyElement1.
 * 3) On the Build menu, click Rebuild Solution.



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 In Microsoft Visual Studio .NET or Microsoft Visual Studio 2005, start a new Windows application by using Visual Basic .NET or Visual Basic 2005. On the View menu, click Solution Explorer. In Solution Explorer, right-click WindowsApplication1, point to Add, and then click Add New Item.

Note In Visual Studio 2005, right-click WindowsApplication1, point to Add, and then click New Item. Under Templates, click to select XML Schema, and then click Open. Right-click Schema designer, and then click View XML Source.  Copy the following code, and then click Paste as HTML in the Edit menu to replace the existing code: <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?> <xs:schema id=&quot;MyDvd&quot; targetNamespace=&quot;http://tempuri.org/MyDvd.xsd&quot; elementFormDefault=&quot;qualified&quot; attributeFormDefault=&quot;qualified&quot; xmlns=&quot;http://tempuri.org/MyDvd.xsd&quot; xmlns:mstns=&quot;http://tempuri.org/MyDvd.xsd&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:msdata=&quot;urn:schemas-microsoft-com:xml-msdata&quot;> <xs:element name=&quot;MyDvd&quot; msdata:IsDataSet=&quot;true&quot;> <xs:complexType> <xs:choice maxOccurs=&quot;unbounded&quot;> <xs:element name=&quot;DVD&quot;> <xs:complexType> <xs:sequence> <xs:element name=&quot;UPC&quot; type=&quot;xs:string&quot; /> <xs:element name=&quot;Title&quot; type=&quot;xs:string&quot; /> <xs:element name=&quot;CoverImageUrl&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /> <xs:element name=&quot;Comments&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /> <xs:element name=&quot;Upc&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> <xs:unique name=&quot;MyDvdKey1&quot; msdata:PrimaryKey=&quot;true&quot;> <xs:selector xpath=&quot;.//mstns:DVD&quot; /> <xs:field xpath=&quot;mstns:UPC&quot; /> </xs:unique> </xs:element> </xs:schema> </li> Right-click the Code editor, and then click View Schema.</li> Right-click the Designer, and then click Generate Dataset.</li> On the Build menu, click Build Solution.

You receive the errors specified in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">