Microsoft KB Archive/815118

= PRB: &quot;System.NullReferenceException&quot; Exception When You Use the DynamicProperties TableName Property in an Untyped Dataset =

Article ID: 815118

Article Last Modified on 7/15/2003

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * 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.



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
 * 1) 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
 * 1) 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.
 * 2) Click Add, and then click Foreign Key Constraint.
 * 3) Change the properties of the newly created constraint to the following:

Parent Table: Authors

Key Columns: id

Foreign key column: author_id

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

Keywords: kberrmsg kbdesigner kbdevstudio kbprb kbconfig KB815118

-

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

© Microsoft Corporation. All rights reserved.