Groups | Blog | Home
all groups > dotnet windows forms designtime > december 2006 >

dotnet windows forms designtime : Understand cicular referencing properties!


Özden Irmak
12/31/2006 2:25:43 AM
Hello,

In my task, I'm scanning all properties of an object and picking up to show
their names in a treeview if it fits some criterias I defined. When
scanning, I've a problem which causes stack overflow error...

This happens when a class does have a circular reference...The best sample
for this can be the treenode class. This class has a refence to it's parent
node also to the treeview control itself. When scanning treenode class,
because of this circular reference, I keep getting back to treeview control
and start scannig all of it's properties which happens infinite times and at
last getting a stack overflow error. The WindowsForms serializer somehow
understands these kind of circular references and instead of trying to
serialize that property, it just sets a reference to the original class.

I'm trying to detect the same sitution and stop going through these circular
referenced properties. Is there any method in .Net to let me understand this
or any method anybody knows?

Thanks in advance...

Regards,

Özden

Mario Vázquez
12/31/2006 8:47:17 AM
Hi Özden,

I suppose you are trying to load recursively the hole treeview. Why you
don't try to load only the first level of the current node?. In that way, it
does'nt matter if you (or somebody) open a node which it was yet visited,
because only the next level will be charged.
Another aproach it will be to determine programatically with the
ReferenceEquals method if the property you are trying to inspect it's
equivalent to a parent object, and cancel the inspection in that case...

Regards,
Mario Vazquez

"Özden Irmak" <ozdenirmak(at)isnet.net.tr> escribió en el mensaje
news:Ove71IHLHHA.1008@TK2MSFTNGP06.phx.gbl...
[quoted text, click to view]

Özden Irmak
1/1/2007 1:52:30 PM
Hello Mario,

Thank you very much for the "ReferenceEquals" tip, it'll be really helpfull
for me.

I think after "ReferenceEquals", feed as needed won't be necessary for me.
Although my code still doesn't work as expected, it seems there are other
problems than self referencing.

Thank you very much again and wish a happy new year for you...

Regards,

Özden

[quoted text, click to view]

AddThis Social Bookmark Button