An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.d

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramya naidu
    New Member
    • Sep 2007
    • 10

    An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.d

    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 other is for data of type Object
    when i run the program i iam grtting the error here

    Code:
    public Sketch FirstData()
    {
    // return Datas[Datas.Count];
    
    foreach (Object data in Datas)
    {
    if (data is Door)
    {
    Door door = (Door)data;
    }
    if (data is Fixture)
    {
    Fixture fixture = (Fixture)data;
    }
    if (data is Wall)
    {
    Wall wall = (Wall)data;
    }
    if (data is Window)
    {
    Window window = (Window)data;
    }
    //return 
    }
    return getSketch(1);
    }
    
    private Sketch getSketch(Int32 id)
    { 
    foreach (Object data in Datas)
    {
    if (data is Door)
    {
    Door door = (Door)data;
    door.Id = id; 
    }
    if (data is Fixture)
    {
    Fixture fixture = (Fixture)data;
    fixture.Id = id;
    }
    if (data is Wall)
    {
    Wall wall = (Wall)data;
    wall.Id = id;
    }
    if (data is Window)
    {
    Window window = (Window)data;
    window.Id = id;
    }
    }
    return getSketch(id);
    }
    An unhandled exception of type 'System.StackOv erflowException ' occurred in mscorlib.dll

    how can i slove this problem?
    can any one help me in this
    Last edited by Plater; Feb 12 '08, 03:08 PM. Reason: added [CODE] tags
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    The stack overflow exception normally happens when you have made a cylical loop out of your functions.
    i.e. FunctionA calls FunctionB and FunctionB calls FunctionA. (There can be more functions involved, but they have to make a loop)

    In your case however, getSketch calls itself for some unknown reason, thus making a cycle with itself. Fix that and your overflow problems should go away.

    Comment

    Working...