title: Cassini/WebServer.WebDev, NUnit and AppDomainUnloadedException
body: <p>I am using Cassini/WebServer.WebDev to run some automated tests of a WebService using NUnit.</p>
  
  <p>I am not doing anything fancy, just</p>
  
  <pre><code>public class WebService{
    Microsoft.VisualStudio.WebHost.Server _server;
  
    public void Start(){
      _server = new Microsoft.VisualStudio.WebHost.Server(_port, "/", _physicalPath);
    }
  
    public void Dispose()
    {
      if (_server != null)
      {
        _server.Stop();
        _server = null;
      }
    }
  }
  [TestFixture]
  public void TestFixture{
    [Test]
    public void Test(){
      using(WebService webService = new WebService()){
        webService.Start();
        // actual test invoking the webservice
      }
    }
  }
  </code></pre>
  
  <p>, but when I run it using nunit-console.exe, I get the following output:</p>
  
  <pre><code>NUnit version 2.5.0.9015 (Beta-2)
  Copyright (C) 2002-2008 Charlie Poole.\r\nCopyright (C) 2002-2004 James W. Newki
  rk, Michael C. Two, Alexei A. Vorontsov.\r\nCopyright (C) 2000-2002 Philip Craig
  .\r\nAll Rights Reserved.
  
  Runtime Environment -
     OS Version: Microsoft Windows NT 6.0.6001 Service Pack 1
    CLR Version: 2.0.50727.1434 ( Net 2.0.50727.1434 )
  
  ProcessModel: Default    DomainUsage: Default
  Execution Runtime: net-2.0.50727.1434
  .....
  Tests run: 5, Errors: 0, Failures: 0, Inconclusive: 0 Time: 28,4538451 seconds
    Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
  
  
  Unhandled exceptions:
  1) TestCase1 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
  2) TestCase2 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
  3) TestCase3 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
  4) TestCase4 : System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
  </code></pre>
  
  <p>If I run nunit-console under the debugger, I get the following output in the debug console:</p>
  
  <pre><code>[...]
  The thread 0x1974 has exited with code 0 (0x0).
  ############################################################################
  ##############                 S U C C E S S               #################
  ############################################################################
  Executed tests       : 5
  Ignored tests        : 0
  Failed tests         : 0
  Unhandled exceptions : 4
  Total time           : 25,7092944 seconds
  ############################################################################
  The thread 0x1bd4 has exited with code 0 (0x0).
  The thread 0x10f8 has exited with code 0 (0x0).
  The thread '&lt;No Name&gt;' (0x1a80) has exited with code 0 (0x0).
  A first chance exception of type 'System.AppDomainUnloadedException' occurred in System.Web.dll
  ##### Unhandled Exception while running 
  System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
     at System.Web.Hosting.ApplicationManager.HostingEnvironmentShutdownComplete(String appId, IApplicationHost appHost)
     at System.Web.Hosting.HostingEnvironment.OnAppDomainUnload(Object unusedObject, EventArgs unusedEventArgs)
  A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
  A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
  A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.Web.dll
  The thread 0x111c has exited with code 0 (0x0).
  The program '[0x1A64] nunit-console.exe: Managed' has exited with code -100 (0xffffff9c).
  </code></pre>
  
  <p>Do anyone have any ideas what could be causing this?</p>