Error AtlasError Documentation and Resolution

.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.

StackOverflowExceptionruntime
Process is terminated due to StackOverflowException.
  • 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.
  1. 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.
  2. Verify that every recursive method has a correct and reachable base case that terminates the recursion.
  3. Check property getters: a common bug is `public string Name { get { return Name; } }` instead of `return _name;`.
  4. Convert recursive algorithms (tree traversal, graph search, deep parsing) to iterative equivalents using an explicit Stack<T> or Queue<T>.
  5. 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`.
  6. 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.
StackOverflowException class — .NET
StackOverflowException in .NET: causes and fixes | Error Atlas