9

How can I diagnose and minimize or prevent AppDomainUnloadedException?

NUnit 2.5.2 consistently throws AppDomainUnloadedException after long (>10s) tests involving PLINQ.

Back in July 2008, Stephen Toub said:

Yes, the scheduler in the CTP doesn't handle thread aborts very well, which frequently causes the process to crash when a live scheduler exists in a domain being shutdown (since AppDomain shut down causes thread aborts on all threads with stack frames in that domain). We're working to harden this for a future release.

I've tried many workarounds, including:

  • Running the test in a separate method to eliminate stray references
  • Specifying /domain:None as an NUNit argument
  • Removing the legacyUnhandledAppDomainPolicy element from nunit-console.exe.config

I can't backgrade NUnit to reduce the odds of the race condition, as I need PLINQ to make my parametric tests go faster. Versions of NUnit without the problem don't support parametric tests.

Garth Kidd
  • 7,264
  • 5
  • 35
  • 36
  • see also http://stackoverflow.com/questions/561402/cassini-webserver-webdev-nunit-and-appdomainunloadedexception for a related problem. This is probably https://bugs.launchpad.net/nunitv2/+bug/423611 – David Schmitt Mar 16 '10 at 11:55
  • 1
    Often such issue caused by wrong disposing of objects instantiated whilst a test startup, see whether you are disposing all resources in right way – sll Sep 08 '11 at 11:50

1 Answers1

1

According to this PLINQ Task Manager thread on the MSDN forums, your problem should be solved; with the latest release of the .NET framework, PLINQ's Task Manager has been to shutdown cleanly on AppDomain unload.

Are you still running into this problem with .NET 4 or 4.5?

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212