473,383 Members | 1,789 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,383 software developers and data experts.

Simple Inheritance - An unhandled exception of type 'System.StackOverflowException'...

Hi everyone

As my expedition into OOP takes another shaky step, I now am getting
the error:

An unhandled exception of type 'System.StackOverflowException' occurred
in xxx.dll.

In my Visit.cls I have got:

public class Visit
{
public FABInfo Info = new FABInfo(); // Line that the error
flags up on.
}
Then in my FABInfo.cls I have got:

public sealed class FABInfo : Visit
{
public string myFunc()
{
return "this.m_sFABSessionID.ToString();";
}
}

When I create an Instance of Visit, I get a loop of
oVisit.Info.Info.Info.Info..... so that is where the problem lies.

Any ideas anyone?

Many thanks

Darren

May 18 '06 #1
12 5080
You create a new Visit, and in the ctor it creates a FABInfo...

*however*, FABInfo *is* a Visit, so this also runs the Visit ctor, and hence
the loop.

What is this trying to represent? Rather than trying to fix the dodgy code,
if you explain what you think you are trying to do, then people can tell you
the right way to do it... which might not resemble your code much ;-p

Marc
May 18 '06 #2
Hey Mark - thanks for the quick reply.

Visit is going to be my base class, and it will maily have properties
in it such as the location of web services, usernames, passwords etc
etc. And from that, there will be a number of child classes such as
Info, Package, Detail.

What I want to do is from Info:Visit, be able to access this.Password
for example and the same from my other child classes.

Does that make sense?

Thanks

Daz

May 18 '06 #3
OK, if I understand your scenario, then the FABInfo creation in the Visit
ctor is erroneous - just ditch it. If you want a FABInfo, then simply use
"new FABInfo()"... since FABInfo derives from Visit this will create the new
FABInfo object by first running the visit ctor, then the FABInfo ctor.

If the Visit genuinely needs a FABInfo, then the object model is screwy;
it's chicken and egg: you can't create a Visit without first successfully
creating a FABInfo, yet a FABInfo /is/ a Visit - so neither can be created.

Marc
May 18 '06 #4
Marc

I sort of understand what you're saying, but I don't think I have
gotten over what I am trying to do.

1) Visit is intended to hold a set variables that are defined when
oVisit is created.

2) FabInfo, FabBasket, FabCoupon etc etc are going to represent
different types of functionality on the site, and ultimately all call
different web services from a given provider.

So, what I wanted to do is configure a Visit object with the usernames,
passwords, urls etc, and then perform my different requests such as:

1) oVisit.Configure(parameters[]); // Initialise my object

2) oVisit.FABInfo.GetInformation(parameters[]);

- or -

3) oVisit.FabBasket.AddItem(parameters[]);

I thought this would save me having to do oFabBasket.Configure() and
oFabInfo.Configure() if I wanted to use both of the classes on the same
page. I could do oVisit.Confgure() and then call
oVisit.FabBasket.Something();

Does that make sense, or do you think I need to review the way I was
planning to set this out?

Thanks

Darren

May 18 '06 #5
I'm going to reply to myself at this point Marc - tell me if you
disagree.

I would be better off with a couple of public (base?) classes:

FabInfo
FabBasket
FabWhatever

And each of thise will inherit

FabConfigure, which can then be configured by oFabInfo.Configure()

I think this would be the right way of doing it. What do you think?

Thanks

Darren

May 18 '06 #6
Quite possibly; you might also look at using an interface rather than a
base-class, but that really comes down to the design
May 18 '06 #7
Another basic point is that the base class shouldn't know about the derived
classes.

It looks like you need three classes (or two and an interface).

1) The base class (perhaps abstract) or interface of...
2) The derived classes
3) The class that holds instances of those derived classes
May 18 '06 #8
Thanks Marc / Piebald

I am fairly sure that I have got it the right way now, and I do need
intervaces for some genric calls that i have got to make.

However, I think I've got it working now with classes, so I am fairly
happy :)

I've had a bit of a crash course in OOP and C# this last 48 hours, and
I'd like to thank everyone for their help!!!

I am on my way now, and the next thing is having to use WebRequest to
consume non-soap web services, so I should imagine i'll be posting
again soon ;)

Many many thanks

Daz

May 19 '06 #9
Search for something I posted a few weeks ago; I posted full code for a
client and server consuming a non-SOAP, xml-based web-service.

Marc
May 19 '06 #10
Thanks Marc - I will have a look now :)

Was it in this group?

Thanks

Darren

May 19 '06 #11
Looking in my outbox: 28th April, titled: Need to write an HTTP server , can
i use a webservice with "NOSOAP"?

Marc
May 22 '06 #12
Hi Mark - found it :)

Thanks - there is a lot of usefull snippets in there that I can have a
look at - you're a star, thankyou so much for your help.

Darren

May 22 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Patrick.O.Ige | last post by:
Error:- System.StackOverflowException: Exception of type System.StackOverflowException was thrown. When is this thrown.. Any ideas
0
by: Nikhil Khade | last post by:
Hello, After around 3 months, I reopened a old VB.NET solutions which used to work (and build) without any errors. Just to test it again, I build it again and it completed, without any errors,...
5
by: Simon Tamman {Uchiha Jax} | last post by:
Now this is bugging me. I just released software for a client and they have reported an unhandled stack overflow exception. My first concern is that the entirity of the UI and any threaded...
1
by: vighnesh | last post by:
Hi All Can anyone please let me know how to catch an unhandled exception like " An Unhandled exception of type 'system.stackoverflowexception' occured in mscorlib.dll " I am unable to catch...
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
1
by: bunnyjoshi | last post by:
"An unhandled exception of type 'System.StackOverflowException' occurred in asset.dll" Above error is occuring when i m debugging my code. asset.dll is file which is created by me n i m using it...
2
geo039
by: geo039 | last post by:
I am a beginner and I have a class that keeps giving me the "An unhandled exception of type 'System.StackOverflowException' occurred" error. I have looked online and do not understand how to correct...
7
by: z71mdridin | last post by:
I have three classes: Public MustInherit Class Animal Public MustOverride Function speak() As String End Class Public Class dog Inherits Animal Public Overrides Function speak() As String...
1
by: ramya naidu | last post by:
Hi I have classes property and sketch in htis property will be linked to skecth class and foure different classes which r linked to the skecth class and two generic list one is for skecth and...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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.