The
StackOverflowException
is triggered by a recursive method that creates a
deep call stack. The problem is linked to the concept of the
stack memory region in general.
Stack Overflow occurs when the stack pointer exceeds the stack bound. The call stack may consist of a limited amount of address space, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When a program attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to overflow, typically resulting in a program crash.
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. Consequently, users are advised to write their code to detect and prevent a stack overflow. For example, if your application depends on recursion, use a counter or a state condition to terminate the recursive loop.
I would suggest you to debug the program. Let it throw the exception. Once exception is thrown and then look at the stack trace. Your stack trace will have a pattern to it showing any number of repeating method calls. Figure out which one of the method calls should not be calling another one in the stack trace and your error will go away. If you are unable to find the pattern in your stack trace, just click on
Improve question and provide the stack trace. We will help you on that.
[Edit 1]
Here I am adding a link which will help you to read stack trace.
Step by Step Guide to Trace the ASP.NET Application for Beginners[
^]
--Amit