Microsoft KB Archive/316839

From BetaArchive Wiki

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 "InitComponent" section of the Form. For example, in Visual C# .NET, you can see the following within the private void InitializeComponent() call:

this.dataset11.DataSetName = "Dataset1";
this.dataset11.Locale = new System.Globalization.CultureInfo("en-US");
//namespace http://schema.microsoft.com/MyDataset1 is hard-coded
this.dataset11.Namespace = "http://schema.microsoft.com/MyDataset1"; 
                

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 "InitComponent" 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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Microsoft Visual C# .NET (or Microsoft Visual Basic .NET) Windows Application.
  2. Add a new DataSet (or schema) file, DataSet1, to the project.
  3. Open the DataSet1 file, and add some sample XSD elements to the schema file; for example, add these lines

    <xs:element name="e1" type="xs:string"></xs:element>
    <xs:element name="e2" type="xs:string"></xs:element>
                            

    between the <xs:choice> tags as follows:

    <xs:choice maxOccurs="unbounded">
      <xs:element name="e1" type="xs:string"></xs:element>
      <xs:element name="e2" type="xs:string"></xs:element>
    </xs:choice>
                        
  4. 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, "http://schemas.microsoft.com/MyDataSet1%22. Make sure that you also change the default namespace in the same element accordingly.
  5. 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.
  6. 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.
  7. 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.
  8. Double-click the Form (or right-click the Form and click View Code). In the Form1.cs file, expand the "#region Windows Form Designer generated code" section, and you will see that the targetNamespace is hard-coded:

    // 
    // dataset11
    // 
    this.dataset11.DataSetName = "Dataset1";
    this.dataset11.Locale = new System.Globalization.CultureInfo("en-US");
    this.dataset11.Namespace = "http://schema.microsoft.com/MyDataset1";
                        


Keywords: kbbug kbvs2002sp1sweep KB316839