Reputation: 141
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();
}
Upvotes: 13
Views: 75130
Reputation: 17186
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.
Upvotes: 39