C# - Determine if class initializaion causes infinite recursion?

Posted by John M on Stack Overflow See other posts from Stack Overflow or by John M
Published on 2010-04-15T14:38:32Z Indexed on 2010/04/15 14:53 UTC
Read the original article Hit count: 388

Filed under:
|
|

I am working on porting a VB6 application to C# (Winforms 3.5) and while doing so I'm trying to break up the functionality into various classes (ie database class, data validation class, string manipulation class).

Right now when I attempt to run the program in Debug mode the program pauses and then crashes with a StackOverFlowException. VS 2008 suggests a infinite recursion cause.

I have been trying to trace what might be causing this recursion and right now my only hypothesis is that class initializations (which I do in the header(?) of each class).

My thought is this:

  • mainForm initializes classA
  • classA initializes classB
  • classB initializes classA
  • ....

Does this make sense or should I be looking elsewhere?

UPDATE1 (a code sample):

mainForm

namespace john
{
    public partial class frmLogin : Form
    {
    stringCustom sc = new sc();

stringCustom

namespace john
{
   class stringCustom
   {
       retrieveValues rv = new retrieveValues();

retrieveValues

namespace john
{
    class retrieveValues
    {
    stringCustom sc = new stringCustom();

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms