.NET process terminated with StackOverflowException
Process is terminated due to StackOverflowException.
The .NET runtime terminated the process with a StackOverflowException because the call stack exceeded its maximum size. Unlike most .NET exceptions this cannot be caught in a try/catch block (since .NET 2.0) — the CLR terminates the process immediately to prevent heap corruption. The cause is almost always infinite or excessively deep recursion.
Process is terminated due to StackOverflowException.
Why it happens
Infinite recursion — a method directly or indirectly calls itself without a correct base case, cycling indefinitely.
Mutual recursion between two or more methods that call each other without a termination condition.
A property getter calling itself, commonly a mistake when a property and a backing field have the same name.
Extremely deep but finite recursion that legitimately exceeds the default thread stack size (1 MB on 32-bit, 4 MB on 64-bit for most thread types).
Serialisation or deserialisation of deeply nested or circular object graphs causing recursive serialiser calls.
How to fix it
Identify the recursive call path — run the application under a debugger and check the call stack when the crash occurs. Look for repeated frames in the stack trace.
Verify that every recursive method has a correct and reachable base case that terminates the recursion.
Check property getters: a common bug is `public string Name { get { return Name; } }` instead of `return _name;`.
Convert recursive algorithms (tree traversal, graph search, deep parsing) to iterative equivalents using an explicit Stack<T> or Queue<T>.
For serialisation of complex graphs, configure the serialiser to handle circular references: in System.Text.Json use `ReferenceHandler.Preserve`, in Newtonsoft.Json use `ReferenceLoopHandling.Ignore` or `Serialize`.
If deep recursion is genuinely required and the depth is bounded but exceeds the default stack: create a new Thread with a larger stack size (`new Thread(Method, stackSizeBytes).Start()`) — this is a workaround, not a fix for unbounded recursion.