StackOverflowException in Typed Dataset

I just killed a System.StackOverflowException that occured when calling the GetChanges() method on my typed Dataset.

I have a couple of tables in the typed dataset that are defined with self relations to represent hierarchies in the data. This relation is also defined in the XSD schema of the typed dataset. Because of a wrong setting in the codegen nullvalue attribute in the xsd the foreign key of the root element in the self related table were set to point to itself:

DepartmentID Name ParentDepartmentID
1 SomeDep 1

Naturally this causes a circular call in certain methods of the dataset, typically GetChanges() because GetChanges() checks if related rows are changed and return these aswell. This causes the StackOverflowException. Quite obvious, but maybe not easy to spot if you didn't explicitly set the foreign key value yourself.

No Comments