By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,168 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,168 IT Pros & Developers. It's quick & easy.

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

P: n/a
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


May 18 '06 #1
Share this Question
Share on Google+
12 Replies

P: n/a
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

May 18 '06 #2

P: n/a
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?



May 18 '06 #3

P: n/a
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.

May 18 '06 #4

P: n/a

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

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



May 18 '06 #5

P: n/a
I'm going to reply to myself at this point Marc - tell me if you

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


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?



May 18 '06 #6

P: n/a
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

P: n/a
Another basic point is that the base class shouldn't know about the derived

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

P: n/a
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


May 19 '06 #9

P: n/a
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.

May 19 '06 #10

P: n/a
Thanks Marc - I will have a look now :)

Was it in this group?



May 19 '06 #11

P: n/a
Looking in my outbox: 28th April, titled: Need to write an HTTP server , can
i use a webservice with "NOSOAP"?

May 22 '06 #12

P: n/a
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.


May 22 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.