Wednesday, October 24, 2007

StackOverflowException: Aspnet_wp.exe (PID: [number]) stopped unexpectedly.

Yesterday I was trying to guess what the hell is going on with my application. You see, I was moving controls from one panel to the other in case the browser was FireFox and I forgot all about it. In Internet Explorer it would work, in FireFox ASP.Net would crash, with a Server not available error and not any relevant message as to why. In the Application Event Log I would get stuff like:
aspnet_wp.exe (PID: 872) stopped unexpectedly.
EventType clr20r3, P1 aspnet_wp.exe, P2 2.0.50727.832, P3 461ef1db, P4 system, P5, P6 461ef191, P7 143a, P8 1f, P9 system.stackoverflowexception, P10 NIL.

and no explanations. Google would give me a lot of links that pertained to WebServices and Asynchronous operations and multi threading, but my application is a simple app. What was going on?

It turns out I was doing this:
Nothing wrong with it, except the control that I was adding was also pnlNoAjax and so it went round and round chasing its own tail until a stack overflow exception was generated.

So, bottom line: try to see if you don't have a control adding itself to its control collection when you meet this weird error. Or, of course, the problem might be in a WebService or threading operation :)