title: exception with no stack trace - how?
body: <p>We have a service which will log unhandled exceptions at the app domain level (via Log4net).</p>
  
  <p>We logged:</p>
  
  <blockquote>
    <p>2014-01-28 16:49:19,636 ERROR [49]  FeedWrapperService - unhandled
    System.NullReferenceException: Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>This exception has no stack trace. How is that possible without doing some crazy things to the exception object?</p>
  
  <p>Our handling code:</p>
  
  <pre><code>AppDomain.CurrentDomain.UnhandledException += LogAnyExceptions;
  
  private void LogAnyExceptions(object sender, UnhandledExceptionEventArgs e)
  {
      log.Error("unhandled", (Exception)e.ExceptionObject);
      throw (Exception)e.ExceptionObject;
  }
  </code></pre>
  
  <p>It occurs to me that the re-throw here is pointless because the AppDomain will come down along with the process anyway, but I don't think it affects our situation.</p>
  
  <p>The windows application event viewer also shows only this null ref exception and no trace.</p>
  
  <p>I've tested the exception handler logging and it successfully logs the stack trace and any inner exception. If it was thrown by our code, we would see a stack trace. If it was thrown by the 3rd party c# library then, again, we would see a stack trace of at least one method (whether it was a re-thrown exception or not). Here we see a managed exception with no stack trace. I don't know how this is possible.</p>
  
  <p>Looking at the decompiled 3rd party library it talks to unmanaged code, and the event that raised this exception is likely in unmanaged land, but how could such a situation cause a managed null ref exception without a stacktrace?</p>
  
  <p>The cause of this problem is intermittent. We've been running this code in production for several months and seen it do this once. It's pretty freaky.</p>
  
  <p>The general consensus is that the system responsible for this kind of problem should be pushed off into a child process so we can deal with the problem and restart safely and automatically, but it would be nice to know what's going on.</p>
  
  <p><strong>Edit to include comment info from below:</strong></p>
  
  <p>My exception is not a standard re-throw, because the stack trace is either null or empty. It does not have the name of the re-throwing method in it. Digging further, the Exception class can be constructed from serialized info, and it looks like the serialized info could contain null strings for stack trace, and potentially that could be created without causing other errors. I guess it might come from there, but I don't know how it originated.</p>