title: APPCRASH StackOverflowException clr.dll c00000fd
body: <p>I am running a .Net console application that executes 24 hrs a day. It has a bug that occurs about once every 6 days. </p>
  
  <p>I would like your assistance to fix this bug. First I will provide some background, and then I will provide the exception messaging.</p>
  
  <p>Unfortunately I do not have steps to reproduce. You will see why as you read on.</p>
  
  <p>First some background:</p>
  
  <p>I have robust exception handling in my code (or so I thought). For example I have a try...catch block in my Main() method that captures any unhandled exceptions and if they are FATAL it restarts the underlying task. It works great for any exceptions generated from my own code. </p>
  
  <p>I cannot explain why the below exception isn't handled in my code. My best guess is that clr.dll exceptions do not get caught within the managed stack. And if that is the case, I do not know how to generate a stack trace. I don't even know where to begin to fix this.</p>
  
  <p>The process I am running is using the following versions and modules:</p>
  
  <ul>
  <li>C# .Net Framework 4.6.1  </li>
  <li>Console App project type</li>
  <li>System.Net.WebClient</li>
  <li>log4net</li>
  <li>Windows 7 64-bit</li>
  </ul>
  
  <p>At the time of the crash I checked RAM and HDD: both have plenty of free space.</p>
  
  <p>About the code I'm executing. The process is a continous loop that downloads data from a website and saves it to a text file. If there is an error, it is logged using log4net.</p>
  
  <p>The basic loop is this:</p>
  
  <pre><code> for (int i = 0; i &lt; 5; i++)
              {
                  try
                  {
                      return new WebClient().DownloadString(url);
                  }
                  catch 
                  {
                      Thread.Sleep(500); // slow it down.
                  }
              }
  </code></pre>
  
  <p>The following is the only message that displays in my console window when the exception occurs: (no stack trace displayed)</p>
  
  <pre><code>Process is terminated due to StackOverflowException
  </code></pre>
  
  <p>My console application completely freezes up and a dialog window pops up with the following information (closing this dialog also terminates my application)</p>
  
  <pre><code> Problem signature:
    Problem Event Name:   APPCRASH
    Application Name: foo.goo.BatchExecutor.exe
    Application Version:  1.0.0.0
    Application Timestamp:    5a50f3eb
    Fault Module Name:    clr.dll
    Fault Module Version: 4.7.2117.0
    Fault Module Timestamp:   59cf5105
    Exception Code:   c00000fd
    Exception Offset: 0002429f
    OS Version:   6.1.7601.2.1.0.256.48
    Locale ID:    1033
    Additional Information 1: 28e8
    Additional Information 2: 28e8aacd8abfe32876bc8363e8e5c526
    Additional Information 3: 6916
    Additional Information 4: 6916665ca52ff482d854f190abcf46b2
  </code></pre>
  
  <p>The only other place I could find information about the crash is in the Windows Event Log:</p>
  
  <pre><code>Log Name:      Application
  Source:        Application Error
  Date:          1/23/2018 5:51:46 PM
  Event ID:      1000
  Task Category: (100)
  Level:         Error
  Keywords:      Classic
  User:          N/A
  Computer:      FOOGOO
  Description:
  Faulting application name: foo.goo.BatchExecutor.exe, version: 1.0.0.0, time stamp: 0x5a50f3eb
  Faulting module name: clr.dll, version: 4.7.2117.0, time stamp: 0x59cf5105
  Exception code: 0xc00000fd
  Fault offset: 0x0002429f
  Faulting process id: 0x1e00
  Faulting application start time: 0x01d39169354e41a7
  Faulting application path: C:\Users\Owner\Desktop\SHARED\foo.goo.BatchExecutor\foo.goo.BatchExecutor.exe
  Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
  Report Id: 21b9b2a4-00a9-11e8-9f6c-94c69110a719
  Event Xml:
  &lt;Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"&gt;
    &lt;System&gt;
      &lt;Provider Name="Application Error" /&gt;
      &lt;EventID Qualifiers="0"&gt;1000&lt;/EventID&gt;
      &lt;Level&gt;2&lt;/Level&gt;
      &lt;Task&gt;100&lt;/Task&gt;
      &lt;Keywords&gt;0x80000000000000&lt;/Keywords&gt;
      &lt;TimeCreated SystemTime="2018-01-24T01:51:46.000000000Z" /&gt;
      &lt;EventRecordID&gt;1852&lt;/EventRecordID&gt;
      &lt;Channel&gt;Application&lt;/Channel&gt;
      &lt;Computer&gt;FOOGOO&lt;/Computer&gt;
      &lt;Security /&gt;
    &lt;/System&gt;
    &lt;EventData&gt;
      &lt;Data&gt;foo.goo.BatchExecutor.exe&lt;/Data&gt;
      &lt;Data&gt;1.0.0.0&lt;/Data&gt;
      &lt;Data&gt;5a50f3eb&lt;/Data&gt;
      &lt;Data&gt;clr.dll&lt;/Data&gt;
      &lt;Data&gt;4.7.2117.0&lt;/Data&gt;
      &lt;Data&gt;59cf5105&lt;/Data&gt;
      &lt;Data&gt;c00000fd&lt;/Data&gt;
      &lt;Data&gt;0002429f&lt;/Data&gt;
      &lt;Data&gt;1e00&lt;/Data&gt;
      &lt;Data&gt;01d39169354e41a7&lt;/Data&gt;
      &lt;Data&gt;C:\Users\Owner\Desktop\SHARED\foo.goo.BatchExecutor\foo.goo.BatchExecutor.exe&lt;/Data&gt;
      &lt;Data&gt;C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll&lt;/Data&gt;
      &lt;Data&gt;21b9b2a4-00a9-11e8-9f6c-94c69110a719&lt;/Data&gt;
    &lt;/EventData&gt;
  &lt;/Event&gt;
  </code></pre>
  
  <p>*****UPDATE WITH SOLUTION WORKAROUND *****</p>
  
  <p>I have given up trying to handle this exception within .Net. I found an effective workaround. This workaround applies to Windows, specifically any version with an Event Viewer.</p>
  
  <p>Workaround Instructions.</p>
  
  <p>1) Open control panel->Admin Tools->Event Viewer->Windows Logs->Applications.</p>
  
  <p>2) Select the offending event. In my case, it is state ERROR, and matches the example that you see above.</p>
  
  <p>3) On the right hand side click "Attach Task to This Event". </p>
  
  <p>4) Complete the wizard. In my case, I restart my application.</p>
  
  <p>5) Save the task.</p>
  
  <p>6) Now switch over to Task Scheduler and find the task. Click Properties. Click through the tabs and configure the Task as you see fit.</p>