Collection indexer causing a stack overflow due to parent property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Geordie said:
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.
 
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.
 
Geordie said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top