title: Async Await Recursion in .NET 4.8 causes StackoverflowException (not in .Net Core 3.1!)
body: <p>Why does the following code cause a StackOverflowException in .Net4.8 with only a 17-depth recursion? However this does not happen in NetCore 3.1 (I can set the count to 10_000 and it still works)</p>
  
  <pre class="lang-cs prettyprint-override"><code>class Program
  {
    static async Task Main(string[] args)
    {
      try
      {
        await TestAsync(17);
      }
      catch(Exception e)
      {
        Console.WriteLine("Exception caught: " + e);
      }
    }
  
    static async Task TestAsync(int count)
    {
      await Task.Run(() =&gt;
      {
        if (count &lt;= 0)
          throw new Exception("ex");
      });
  
      Console.WriteLine(count);
      await TestAsync2(count);
    }
  
    static async Task TestAsync2(int count) =&gt; await TestAsync3(count);
    static async Task TestAsync3(int count) =&gt; await TestAsync4(count);
    static async Task TestAsync4(int count) =&gt; await TestAsync5(count);
    static async Task TestAsync5(int count) =&gt; await TestAsync6(count);
    static async Task TestAsync6(int count) =&gt; await TestAsync(count - 1);
  }
  </code></pre>
  
  <p>Is this a known bug in .Net 4.8? I would except a lot more than 17 levels of recursion in such a function... Does this effectively mean writing recursions with async/await is not recommended?</p>
  
  <p><strong>Update: Simplified version</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>class Program
  {
    // needs to be compiled as AnyCpu Prefer 64-bit
    static async Task Main(string[] args)
    {
      try
      {
        await TestAsync(97); // 96 still works
      }
      catch(Exception e)
      {
        Console.WriteLine("Exception caught: " + e);
      }
    }
  
    static async Task TestAsync(int count)
    {
      await Task.Run(() =&gt;
      {
        if (count &lt;= 0)
          throw new Exception("ex");
      });
  
      Console.WriteLine(count);
      await TestAsync(count-1);
    }
  }
  </code></pre>
  
  <p>It only happens so fast when choosing <strong>Any Cpu</strong> with Prefer <strong>32-bit disabled</strong>, but is reproducable on multiple machines (Windows 1903 and 1909) on multiple .net versions (.Net 4.7.2 and .Net 4.8)</p>