473,373 Members | 1,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 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 1664
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Will Pittenger | last post by:
I have a Control derived class. When the parent of the control changes the control's Location property, the stack overflows. I have not found a way to find out what was on the stack when it does...
9
by: Gerald Lightsey | last post by:
I am doing some work that involves automating MS MapPoint 2002. The object model is documented in the context of Visual Basic 6.0. A typical example follows. 'Output first result of find...
4
by: Matt | last post by:
Hi, I've been thinking about how to do this, but can't think of a solution. I have a class that is derived from System.Web.UI.WebControls.DataGrid which works a treat, but I'd like to extend...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.