StackOverflowException in

Hi Experts,
I have a function which is throwing StackOverflowException.

t thorws message,
StackOverflowException was unhandled.
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

 public DataTable Recurssive(string NewWduserId, string WduserId, DataTable currentTeam, DataTable dtFinal, int HierachyId)
            DataRow[] currentTeam1 = currentTeam.Select("WduserId = '" + WduserId + "'");
            string TM = string.Empty;
            if (currentTeam1.Length > 0)
                if (WduserId.Trim() != Convert.ToString(currentTeam1[0]["SuperVisor"]).Trim())
                    DataRow[] dr = currentTeam.Select("Supervisor ='" + Convert.ToString(currentTeam1[0]["SuperVisor"]) + "'");
                    if (dr.Length > 0)
                        DataRow drn = dtFinal.NewRow();
                        DataRow[] drWd = currentTeam.Select("WduserId = '" + NewWduserId + "'");
                        drn["wduserid"] = NewWduserId;
                        drn["empname"] = drWd[0]["empname"];
                        drn["supervisorid"] = dr[0]["supervisor"];
                        drn["supervisorname"] = dr[0]["supervisorname"];
                        drn["designation"] = dr[0]["designationname"];
                        drn["compemailId"] = dr[0]["compemailId"];
                        drn["StructureId"] = HierachyId;
                        HierachyId = HierachyId + 1;
                        Recurssive(NewWduserId, dr[0]["SuperVisor"].ToString(), currentTeam, dtFinal, HierachyId);
            return dtFinal;

What's wrong going on?
Johny BravoAsked:
Who is Participating?
That error is usually due to an infinite loop or an endless recursion. Check the condition for calling your recurssive procedure.
You do not modify DataTable currentTeam inside this method.
So, all conditions are allways true and you allways add new row to dtFinal. Infinitely.
Johny BravoAuthor Commented:
Thanks for the guidance.The issue is resolved
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.