In a ASP.Net web application, when you have a stack intensive operation to run, a stackoverflow exception is thrown on IIS when the stack size crosses the IIS set limit of 256K. A regular winform application however has a limit of 1MB. So the exception would not occur when running the same operation in a Winform application.

There is no recursion or any other code specific issues here.

There are ways to work around the problem like using EditBin on w3wp.exe, but it’s not supported.

Other option is to modify the actual code to reduce the size of locals and there by the stack size, which might involve significant design, code changes.

But the following approach solves the issue when running the Stack intensive operation on a separate thread, explicitly specifying the size of 1MB.

What are you doing that makes the stack so huge? It could be that changing the design would be a very good thing to do anyway...
–
Jon SkeetAug 26 '10 at 17:15

Jon, agreed it needs a design change, but due to efforts and complexity involved, it has a bigger risk. End of the day we can't ship it on time :) Why is the stack huge? Several functions carry locals that are very big in size, we have very less control over this "generated code" :)
–
VinAug 26 '10 at 17:17