Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

I wrote a code in asp.net that read data from files and draw a graph.

It worked but after awhile when i run the program, this exception arise

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

in this statement in the code:

if (File.Exists(fName)) <----(here is the exception)
{
    stream = File.Open(fName, FileMode.Open);
    g_day = Deserialize(stream);
    stream.Close();
    int cn = 0;
    if (g_day.Values.Count != 0)
        cn = g_day.Values[g_day.Values.Count - 1].Value;
    Label1.Text = cn.ToString();
}
like image 561
Sahar Avatar asked May 06 '10 15:05

Sahar


1 Answers

Your function is probably calling itself recursively an infinite number of times. Sometimes this happens indirectly (you call a method in the BCL and it calls back to your code, and this keeps repeating). File.Exists is probably not the culprit. Look at your call stack when the error occurs.

like image 113
Qwertie Avatar answered Oct 22 '22 16:10

Qwertie