Microsoft KB Archive/316839

= BUG: The targetNamespace property of DataSet instances is hard-coded in Windows Form constructor =

Article ID: 316839

Article Last Modified on 9/15/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q316839



SYMPTOMS
When you generate a DataSet object from an XSD schema file and then add the DataSet to a Windows Form, the targetNamespace property of the schema file on which the DataSet is based is hard-coded in the &quot;InitComponent&quot; section of the Form. For example, in Visual C# .NET, you can see the following within the private void InitializeComponent call: this.dataset11.DataSetName = &quot;Dataset1&quot;; this.dataset11.Locale = new System.Globalization.CultureInfo(&quot;en-US&quot;); //namespace http://schema.microsoft.com/MyDataset1 is hard-coded this.dataset11.Namespace = &quot;http://schema.microsoft.com/MyDataset1&quot;; If the targetNamespace in the DataSet schema is changed for any reason, a few scenarios may stop working; for example, writing the DataSet out to an XML file, reading it back in, and persisting the DataSet with the correct namespace.



CAUSE
If you change the namespace of an XSD schema in the DataSet Designer, new instances of the typed DataSet get the updated namespace, but the existing instance is not changed automatically.



RESOLUTION
To work around the problem, manually change the namespace in the &quot;InitComponent&quot; section of the Form, or delete and then read the typed DataSet after changing the namespace.



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 Behavior
 Create a new Microsoft Visual C# .NET (or Microsoft Visual Basic .NET) Windows Application. Add a new DataSet (or schema) file, DataSet1, to the project.  Open the DataSet1 file, and add some sample XSD elements to the schema file; for example, add these lines   between the <xs:choice> tags as follows: <xs:choice maxOccurs=&quot;unbounded&quot;> </xs:element> </xs:element> </xs:choice> </li> Click the XML tab at the bottom of the DataSet Designer to switch to the XML view of the schema. Manually change the targetNamespace attribute on xs:schema element; for example, &quot;http://schemas.microsoft.com/MyDataSet1&quot;. Make sure that you also change the default namespace in the same element accordingly.</li> Click the DataSet tab to switch views. If there are any errors in the schema file, you will see the output in the DataSet Designer. Correct any errors.</li> To generate a Wrapper class for this Dataset, on the Schema menu, click Generate Dataset. Make sure that you are on the DataSet view of DataSet1.xsd.</li> Open the Windows Form. Drag a DataSet object from the Data tab of the toolbox to the Form, and pick the strongly typed dataset (DataSet1) that you just created.</li>  Double-click the Form (or right-click the Form and click View Code). In the Form1.cs file, expand the &quot;#region Windows Form Designer generated code&quot; section, and you will see that the targetNamespace is hard-coded: // // dataset11 // this.dataset11.DataSetName = &quot;Dataset1&quot;; this.dataset11.Locale = new System.Globalization.CultureInfo(&quot;en-US&quot;); this.dataset11.Namespace = &quot;http://schema.microsoft.com/MyDataset1&quot;; </li></ol>

Keywords: kbbug kbvs2002sp1sweep KB316839

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.