Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent AppDomainUnloadedException after NUnit tests PLINQ code?

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.

like image 864
Garth Kidd Avatar asked Aug 27 '09 10:08

Garth Kidd


1 Answers

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?

like image 156
Judah Gabriel Himango Avatar answered Sep 21 '22 10:09

Judah Gabriel Himango