I've been writing a web application targeted to .NET framework v3.5 with Visual Studio 2013.
Indirect recursion in it someties cause a StackOverflowException so I wrote a method which checks if the stack overflows.
public static void CheckStackOverflow() {
StackTrace stackTrace = new StackTrace();
StackDepth = stackTrace.GetFrames().Length;
if(StackDepth > MAXIMUM_STACK_DEPTH) {
throw new StackOverflowException("StackOverflow detected.");
}
}
The problem is that a StackOverflowException occurs at the first line, i.e. new StackTrace()
, so I cannot take care of it.
I know that calling to StackTrace() also deepens the stack by a couple of levels, so I understand this can happen. However, there is some food for thought:
- Opting for Visual Studio(ASP.NET) Development Server(hereinafter Cassini) in Visual Studio 2012 got no problem, so my IIS settings or something like that is a suspect.
- The stack, at the time the exception occured, was NOT really deep enough.
This only happens on debugging. Regardless of the configuration(i.e. Debug/Release).
Edit: I tried to changed IIS Express settings and it made no differences. Also, Trying Local IIS option got no luck, either. So,
if(RunningWithVisualStudio) { // Start Debugging or Without Debugging
if(UsingCassini) {
throw new StackOrverflowException("A catchable exception."); // expected
} else {
throw new StackOverflowException("I cannot catch this dang exception.");
}
} else { // publish on the identical ApplicationPool.
throw new StackOrverflowException("A catchable exception."); // expected
}
I thought I'd made mistakes configuring IIS Express but now I'm totally lost.