Search code examples
c#.netstack-overflowclr

Does the output "Stack overflow. Repeat 24047 times ..." mean that I found a bug in dotnet?


I wrote new code for my project and when I run my unit tests, I noticed that dotnet crashes.

But I did not know why. So I moved some of the code to a console application and run that. Then I got this output:

Stack overflow.
Repeat 24047 times:
--------------------------------
   at [[ class and method names here ]]
--------------------------------
   at [[ class and method names here ]]

After some time, there is a StackOverflowException: The runtime refused to evaluate the expression at this time. Afterwards, dotnet crashes again.

That's it. So the build process (compiling) is successful, but it seems that the CLR crashes??

Is this my fault or is this a bug in DotNet?

Edit: Here is some code and also the explanation for my problem. It was a recursion mistake on my site: https://dotnetfiddle.net/RD69Mk


Solution

  • It's your fault. You have a recursive method call and you should have a look into the mentioned class and methods that are listed. Do not report to Microsoft.

    Instead, use a debugger and step through your code to see what it does and why it does that.

    The simplest program to reproduce the problem is

    class Program
    {
        static void Main()
        {
            Main();
        }
    }
    

    Is it a valid C# program? Yes. Does it make sense? No. Is it Microsoft's problem? No.

    A recursive implementation needs a stopping condition, i.e. a case where it breaks out of the repeating call to itself.