You receive "'columnName' is already declared" errors when you build a Visual Basic .NET or Visual Basic 2005 project (818218)



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Microsoft Visual Studio .NET or Microsoft Visual Studio 2005, start a new Windows application by using Visual Basic .NET or Visual Basic 2005.
  2. On the View menu, click Solution Explorer.
  3. 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.
  4. Under Templates, click to select XML Schema, and then click Open.
  5. Right-click Schema designer, and then click View XML Source.
  6. Copy the following code, and then click Paste as HTML in the Edit menu to replace the existing code:
    <?xml version="1.0" encoding="utf-8" ?>
    <xs:schema id="MyDvd" targetNamespace="http://tempuri.org/MyDvd.xsd"
    elementFormDefault="qualified" attributeFormDefault="qualified" xmlns="http://tempuri.org/MyDvd.xsd"
    xmlns:mstns="http://tempuri.org/MyDvd.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    	<xs:element name="MyDvd" msdata:IsDataSet="true">
    		<xs:complexType>
    			<xs:choice maxOccurs="unbounded">
    				<xs:element name="DVD">
    					<xs:complexType>
    						<xs:sequence>
    							<xs:element name="UPC" type="xs:string" />
    							<xs:element name="Title" type="xs:string" />
    							<xs:element name="CoverImageUrl" type="xs:string" minOccurs="0" />
    							<xs:element name="Comments" type="xs:string" minOccurs="0" />
    							<xs:element name="Upc" type="xs:string" minOccurs="0" />
    						</xs:sequence>
    					</xs:complexType>
    				</xs:element>
    			</xs:choice>
    		</xs:complexType>
    		<xs:unique name="MyDvdKey1" msdata:PrimaryKey="true">
    			<xs:selector xpath=".//mstns:DVD" />
    			<xs:field xpath="mstns:UPC" />
    		</xs:unique>
    	</xs:element>
    </xs:schema>
    
  7. Right-click the Code editor, and then click View Schema.
  8. Right-click the Designer, and then click Generate Dataset.
  9. On the Build menu, click Build Solution.

    You receive the errors specified in the "Symptoms" section of this article.

REFERENCES

For more information, visit the following MSDN Web site:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbSchema kbXML kbprb KB818218 kbAudDeveloper