title: NetworkInterface.GetAllNetworkInterfaces causes AppDomain.UnhandledException to stop firing on Windows XP Embedded
body: <p>I have an application that targets desktop OSes (XP, Vista, Win7) as well as mobile devices running Windows XP Embedded. All platforms are running the full .Net Framework, <em>not</em> the Compact Framework. The app uses the <code>AppDomain.UnhandledException</code> event to detect and log any fatal application errors. Nothing unusual there, and it works perfectly -- at least on the desktop OSes. </p>
  
  <p>At another place in the application, there is a piece of code that calls the <code>NetworkInterface.GetAllNetworkInterfaces</code> method to get a list of NICs on the machine. On Windows XP Embedded -- but not the desktop OSes -- once this method has been called, the <code>AppDomain.UnhandledException</code> event no longer fires when unhandled exceptions occur. Instead, the app just crashes, without even displaying the standard .Net crash dialog.</p>
  
  <p>Is this a known bug, or am I doing something wrong? Does anybody know a workaround for this?</p>
  
  <p>Here is a sample application that reproduces the problem. This example is written in WinForms, but the same problem occurs in WPF as well.</p>
  
  <pre><code>using System;
  using System.Net.NetworkInformation;
  using System.Threading;
  using System.Windows.Forms;
  
  namespace BugDemo
  {
      public class BugDemoForm : Form
      {
          /// &lt;summary&gt;
          /// This is the entry point of the application.
          /// &lt;/summary&gt;
          [STAThread]
          static void Main()
          {
              AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
              Application.Run(new BugDemoForm());
          }
  
          /// &lt;summary&gt;
          /// Sets up a simple form with two buttons for reproducing the bug.
          /// &lt;/summary&gt;
          public BugDemoForm()
          {
              Padding = new Padding(15);
              Width = 400;
              int halfHeight = (ClientRectangle.Height / 2) - Padding.Vertical;
  
              Button exceptionButton = new Button();
              exceptionButton.Dock = DockStyle.Top;
              exceptionButton.Height = halfHeight;
              exceptionButton.Text = "Test the AppDomain.UnhandledException method";
              exceptionButton.Click += exceptionButton_Click;
              Controls.Add(exceptionButton);
  
              Button networkInterfacesButton = new Button();
              networkInterfacesButton.Dock = DockStyle.Bottom;
              networkInterfacesButton.Height = halfHeight;
              networkInterfacesButton.Text = "Call the NetworkInterface.GetAllNetworkInterfaces method";
              networkInterfacesButton.Click += networkInterfacesButton_Click;
              Controls.Add(networkInterfacesButton);
          }
  
          /// &lt;summary&gt;
          /// Throws an exception on a background thread. 
          /// This will cause the &lt;see cref="AppDomain.UnhandledException"/&gt; event to fire.
          /// &lt;/summary&gt;
          private static void exceptionButton_Click(object sender, EventArgs e)
          {
              ThreadPool.QueueUserWorkItem(
                  delegate(object state)
                  {
                      throw new ApplicationException();
                  });
          }
  
          /// &lt;summary&gt;
          /// Calls the &lt;see cref="NetworkInterface.GetAllNetworkInterfaces"/&gt; method.
          /// Once this method is called, the &lt;see cref="AppDomain.UnhandledException"/&gt; event
          /// will no longer fire.
          /// &lt;/summary&gt;
          private static void networkInterfacesButton_Click(object sender, EventArgs e)
          {
              NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
              MessageBox.Show("There are " + nics.Length + " network interfaces on this machine.\n\n"
                  + "Now that the NetworkInterface.GetAllNetworkInterfaces method has been called, "
                  + "the AppDomain.UnhandledException event will no longer fire when running on "
                  + "Windows XP Embedded.");
          }
  
          /// &lt;summary&gt;
          /// Fires whenever an unhandled exception occurs on a background thread.
          /// However, once the &lt;see cref="NetworkInterface.GetAllNetworkInterfaces"/&gt; method has been
          /// called, this event no longer fires.
          /// &lt;/summary&gt;
          private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
          {
              MessageBox.Show("The AppDomain.UnhandledException event fired successfully.\n"
                  + "The app will now crash, as expected.");
          }
      }
  }
  </code></pre>