How can I prevent AppDomainUnloadedException after NUnit tests PLINQ code?
Asked Answered
A

1

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.

Auburn answered 27/8, 2009 at 10:28 Comment(2)
see also #561902 for a related problem. This is probably bugs.launchpad.net/nunitv2/+bug/423611Reach
Often such issue caused by wrong disposing of objects instantiated whilst a test startup, see whether you are disposing all resources in right wayTreasury
S
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?

Stonewort answered 5/10, 2011 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.