PRB: "System.NullReferenceException" Exception When You Use the DynamicProperties TableName Property in an Untyped Dataset (815118)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition

SYMPTOMS

When you modify the TableName property of the table in a configuration file, and the table has a relation contraint or a foreign key constraint, you may receive the System.NullReferenceException exception.

CAUSE

Microsoft Visual Studio designer does not store relation information or foreign key constraint information in the configuration file. However, when you use the DynamicProperties node to modify the TableName property, the constraint is not changed and the runtime continues to search for the hard-coded TableName. This behavior causes the exception.

RESOLUTION

To resolve this problem, do not use or modify the Dynamic Properties for the TableName property while you use a relation or a foreign key constraint.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

Note You can reproduce this behavior in Microsoft Visual C# .NET, Microsoft Visual Basic .NET, Microsoft Visual J# .NET, and Microsoft Visual C++ .NET. This article describes the tasks that you can perform by using Visual C# .NET.
  1. Start Visual Studio .NET.
  2. On the File menu, click New, and then click Project.
  3. Click Visual C# Projects under Project Types, and then click Windows Application under Templates. By default, Form1 is created.
  4. Drag a DataSet control from the toolbox to Form1. Click Untyped Dataset, and then click OK.
  5. In the Properties pane of dataset1, click Tables under Data, and then click the ellipsis (...) button.
  6. In the Tables Collection Editor dialog box, click Add under Members to add a new member in the dataset1.Tables collection.
  7. In the TableName text box, replace Table1 with Authors.
  8. Under Design, replace dataTable1 with Authors in the (Name) text box.
  9. Repeat step 6 through 8 to add one more table. In the TableName text box of the new table, type Books, and then in the (Name) text box, type Books.
  10. In the Properties for the Authors table, click Columns, and then click the ellipsis (...) button to open the Columns Collection Editor dialog box.
  11. Click Add to add new member. Change the properties of this column to the following:
    ColumnName: id
    Unique: True
  12. Repeat step 10 and 11 for the Books table to add two new members. Change the properties of the two newly created columns to the following:

    Column 1
    ColumnName: id
    Unique: True

    Column 2
    ColumnName: author_id
  13. In the Properties for the Books table, click Constraints under Data, and then click the ellipsis (...) button to open the Constraints Collection Editor dialog box.
  14. Click Add, and then click Foreign Key Constraint.
  15. Change the properties of the newly created constraint to the following:
    Parent Table: Authors
    Key Columns: id
    Foreign key column: author_id

    Click OK.
  16. In the Authors table, expand the DynamicProperties node, and then click the ellipsis (...) button to open the Dynamic Property dialog box.
  17. Under Properties, click TableName, and then click OK.
  18. Build and run the project.
  19. Edit the project.exe.config file, and then modify "Authors.TableName" (for example: "MyAuthors"). Save the file to the same directory where project.exe file is saved.
  20. Run the application without compiling the project. You may receive the exception that is described in the "Symptoms" section of this article.

Modification Type:MinorLast Reviewed:7/15/2003
Keywords:kbConfig kberrmsg kbDevStudio kbDesigner kbprb KB815118 kbAudDeveloper