473,396 Members | 2,016 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,396 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 1666
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.