471,337 Members | 977 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Collection indexer causing a stack overflow due to parent property

Hi,

I'm in the process of converting a production VS 2003 application to VS
2005. To simplify the conversion I'm converting a small piece at a time and
then unit testing the code to confirm it converted correctly. The application
consists of 10 seperate projects.

I have hit a problem with converting the core object model project. The
object model consists of hierarchical data some of which implement the
IBinding and IBindingList interfaces. Part of the interface implemenation
includes the creation of a parent property. It appears that it is this
property that is causing the problem.

I have been able to recreate the problem in a striped down version of the
object model. If I remove the parent properties the indexer works correctly.
With the parent properties I get the stack overflow error.

Since this code works well in framework 1.1 and is failing in 2.0 I have 2
questions. 1) What has changed to cause this problem. 2) How do I code
around this problem.

With respect to the second question the only option I have been able to come
up with is to use a pointer as described in the following link...

http://www.developerfusion.co.uk/show/2929/2/

Any advice, answers and thought would welcome.

Thanks in advance.
Dec 23 '05 #1
4 1553
Geordie <Ge*****@discussions.microsoft.com> wrote:
I have been able to recreate the problem in a striped down version of the
object model. If I remove the parent properties the indexer works correctly.
With the parent properties I get the stack overflow error.


When you do what? It sounds like you've got a short but complete
program which will demonstrate the problem - please post it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 23 '05 #2
The simplified project is to big to post. The error occurs when I try to
index the collection i.e. salesOrders[0].salesOrderItem.Add(item);

Here is the indexer code in the collection class.

public virtual object this[int index]
{
get
{
return (object)this.List[index];
}
}

The object classes (in this case the SalesOrderItem class) contain this code;

private SalesOrderItems parent;
internal SalesOrderItems Parent
{
get
{
return parent;
}
set
{
parent = value;
}
}

I hope this helps answer your question.

"Jon Skeet [C# MVP]" wrote:
Geordie <Ge*****@discussions.microsoft.com> wrote:
I have been able to recreate the problem in a striped down version of the
object model. If I remove the parent properties the indexer works correctly.
With the parent properties I get the stack overflow error.


When you do what? It sounds like you've got a short but complete
program which will demonstrate the problem - please post it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 23 '05 #3
Geordie <Ge*****@discussions.microsoft.com> wrote:
The simplified project is to big to post.
That suggests it hasn't been stripped down enough :)

See http://www.pobox.com/~skeet/csharp/complete.html
The error occurs when I try to
index the collection i.e. salesOrders[0].salesOrderItem.Add(item);

Here is the indexer code in the collection class.

public virtual object this[int index]
{
get
{
return (object)this.List[index];
}
}
And what does the List property return?
The object classes (in this case the SalesOrderItem class) contain this code;

private SalesOrderItems parent;
internal SalesOrderItems Parent
{
get
{
return parent;
}
set
{
parent = value;
}
}

I hope this helps answer your question.


Not sure where the Parent property comes in here, as it's not
referenced in any of the code you've posted.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 23 '05 #4
After further code modifications I was able to show that the indexer worked
with the parent properties populated. The part of the code that is causing
the problem is the impementation of the IBinding interface.

I was able to determine that this interface has been changed in version 2
according to the WindowsForms.Net (see link below).

http://www.windowsforms.net/Samples/...ding%20FAQ.doc
"Geordie" wrote:
Hi,

I'm in the process of converting a production VS 2003 application to VS
2005. To simplify the conversion I'm converting a small piece at a time and
then unit testing the code to confirm it converted correctly. The application
consists of 10 seperate projects.

I have hit a problem with converting the core object model project. The
object model consists of hierarchical data some of which implement the
IBinding and IBindingList interfaces. Part of the interface implemenation
includes the creation of a parent property. It appears that it is this
property that is causing the problem.

I have been able to recreate the problem in a striped down version of the
object model. If I remove the parent properties the indexer works correctly.
With the parent properties I get the stack overflow error.

Since this code works well in framework 1.1 and is failing in 2.0 I have 2
questions. 1) What has changed to cause this problem. 2) How do I code
around this problem.

With respect to the second question the only option I have been able to come
up with is to use a pointer as described in the following link...

http://www.developerfusion.co.uk/show/2929/2/

Any advice, answers and thought would welcome.

Thanks in advance.

Dec 24 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.