Merge lp:~mfenniak/nunitv2/AppDomainUnloadFailure into lp:nunitv2

Proposed by Mathieu Fenniak
Status: Merged
Approved by: Charlie Poole
Approved revision: 3190
Merge reported by: Charlie Poole
Merged at revision: not available
Proposed branch: lp:~mfenniak/nunitv2/AppDomainUnloadFailure
Merge into: lp:nunitv2
Diff against target: 50 lines (+22/-2)
2 files modified
src/ClientUtilities/tests/DomainManagerTests.cs (+10/-0)
src/ClientUtilities/util/Services/DomainManager.cs (+12/-2)
To merge this branch: bzr merge lp:~mfenniak/nunitv2/AppDomainUnloadFailure
Reviewer Review Type Date Requested Status
Charlie Poole Pending
Review via email: mp+32099@code.launchpad.net

Description of the change

Fixes an occasional unhandled exception from NUnit, when attempting to unload an AppDomain that has already been unloaded.

Unhandled Exception:
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
at System.AppDomain.get_FriendlyName()
at NUnit.Util.DomainManager.DomainUnloader.Unload()
at NUnit.Util.TestDomain.Unload()
at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
at NUnit.ConsoleRunner.Runner.Main(String[] args)

The fix is to abort without error when the target AppDomain is already unloaded.

To post a comment you must log in.
Revision history for this message
Charlie Poole (charlie.poole) wrote :

Not sure why this hasn't been merged before, but I'll do it now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ClientUtilities/tests/DomainManagerTests.cs'
2--- src/ClientUtilities/tests/DomainManagerTests.cs 2010-04-19 03:57:21 +0000
3+++ src/ClientUtilities/tests/DomainManagerTests.cs 2010-08-09 13:23:42 +0000
4@@ -76,6 +76,16 @@
5 }
6
7 return path;
8+ }
9+
10+ [Test]
11+ public void UnloadUnloadedDomain()
12+ {
13+ AppDomain domain = AppDomain.CreateDomain("DomainManagerTests-domain");
14+ AppDomain.Unload(domain);
15+
16+ DomainManager manager = new DomainManager();
17+ manager.Unload(domain);
18 }
19 }
20 }
21
22=== modified file 'src/ClientUtilities/util/Services/DomainManager.cs'
23--- src/ClientUtilities/util/Services/DomainManager.cs 2010-07-31 21:34:07 +0000
24+++ src/ClientUtilities/util/Services/DomainManager.cs 2010-08-09 13:23:42 +0000
25@@ -151,13 +151,23 @@
26
27 public void Unload()
28 {
29- log.Info("Unloading AppDomain " + domain.FriendlyName);
30+ string domainName;
31+ try
32+ {
33+ domainName = domain.FriendlyName;
34+ }
35+ catch (AppDomainUnloadedException)
36+ {
37+ return;
38+ }
39+
40+ log.Info("Unloading AppDomain " + domainName);
41
42 thread = new Thread(new ThreadStart(UnloadOnThread));
43 thread.Start();
44 if (!thread.Join(20000))
45 {
46- log.Error("Unable to unload AppDomain {0}, Unload thread timed out", domain.FriendlyName);
47+ log.Error("Unable to unload AppDomain {0}, Unload thread timed out", domainName);
48 thread.Abort();
49 }
50 }

Subscribers

People subscribed via source and target branches

to status/vote changes: