0

I made a stupid mistake, I called myControl.Controls.Add(myControl);. Easy enough. The interesting thing is that this cause IIS to crash and the exception was thrown in the actual framework. I didn't even break and let me debug, it just fell apart.

It seems like this should have been handled better by the .NET framework than it was. Or should it? Is this expected behavior with a mistake like this, or could it have been handled more elegantly by the debugger?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stephen Collins
  • 3,523
  • 8
  • 40
  • 61
  • 1
    This is completely normal. How is the computer suppose to run nonsensical code? ;p – leppie Jan 04 '13 at 05:06
  • I assume it caused the app domain in which it was running to crash, not IIS. There's a difference there; IIS may manage many worker processes. And yes, I would expect that with a SO exception. – Tim M. Jan 04 '13 at 05:17
  • If it hurts when you do that....don't do that. – Steve Wellens Jan 04 '13 at 05:22

1 Answers1

4

This is a documented behavior - see the documentation at MSDN

Here's the relevant quote:

Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default.

EDIT:
From debugging perspective, as apparently there is no stack trace, if the issue is reproducible then relevant code walk-through (or debugging before actual exception occurs) may pin-point the issue. Yet another way could be to use IIS Debug Diagnostics tool and get the error details and crash dump. Refer this SO answer that seems to suggest similar ways.

Community
  • 1
  • 1
VinayC
  • 47,395
  • 5
  • 59
  • 72