From 29dd0a50d7deaab506fc2d3c74429b33746738c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:07:29 +0000 Subject: [PATCH 1/5] Initial plan From 643f608eee5418a8cfc85d3b1d7b5a30143a0807 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:11:39 +0000 Subject: [PATCH 2/5] Fix ObjectDisposedException: swap mre/watcher declaration order in BuildsWhileBuildIsRunningOnServer Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com> --- src/MSBuild.UnitTests/MSBuildServer_Tests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs index a820d138bf8..ee05f747d53 100644 --- a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs +++ b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs @@ -190,8 +190,8 @@ public void BuildsWhileBuildIsRunningOnServer() _env.WithTransientProcess(pidOfServerProcess); string? dir = Path.GetDirectoryName(markerFile.Path); - using var watcher = new System.IO.FileSystemWatcher(dir!); using ManualResetEvent mre = new ManualResetEvent(false); + using var watcher = new System.IO.FileSystemWatcher(dir!); watcher.Created += (o, e) => { _output.WriteLine($"The marker file {markerFile.Path} was created. The build task has been started."); From b1e845d501d69b169fabd75a1de9cca9cd00c1d1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:34:37 +0000 Subject: [PATCH 3/5] Add comment explaining mre/watcher declaration order to prevent future reordering Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com> --- src/MSBuild.UnitTests/MSBuildServer_Tests.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs index ee05f747d53..cfc7201fc6f 100644 --- a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs +++ b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs @@ -190,6 +190,11 @@ public void BuildsWhileBuildIsRunningOnServer() _env.WithTransientProcess(pidOfServerProcess); string? dir = Path.GetDirectoryName(markerFile.Path); + // mre must be declared before watcher so that it is disposed after watcher. + // With `using var`, disposal happens in reverse declaration order, so watcher + // is disposed first (stopping event delivery) before mre is disposed. Reversing + // this order would allow late FileSystemWatcher callbacks to call mre.Set() on + // a disposed ManualResetEvent, causing an ObjectDisposedException. using ManualResetEvent mre = new ManualResetEvent(false); using var watcher = new System.IO.FileSystemWatcher(dir!); watcher.Created += (o, e) => From b882530b8454139d7ac315d286082be1167dd6ec Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Mon, 2 Mar 2026 14:37:00 -0600 Subject: [PATCH 4/5] simplify comment --- src/MSBuild.UnitTests/MSBuildServer_Tests.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs index cfc7201fc6f..5c38a41f3a0 100644 --- a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs +++ b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs @@ -191,10 +191,8 @@ public void BuildsWhileBuildIsRunningOnServer() string? dir = Path.GetDirectoryName(markerFile.Path); // mre must be declared before watcher so that it is disposed after watcher. - // With `using var`, disposal happens in reverse declaration order, so watcher - // is disposed first (stopping event delivery) before mre is disposed. Reversing - // this order would allow late FileSystemWatcher callbacks to call mre.Set() on - // a disposed ManualResetEvent, causing an ObjectDisposedException. + // Reversing this order would allow late FileSystemWatcher callbacks to call + // mre.Set() on a disposed ManualResetEvent, causing an ObjectDisposedException. using ManualResetEvent mre = new ManualResetEvent(false); using var watcher = new System.IO.FileSystemWatcher(dir!); watcher.Created += (o, e) => From 1f85ee009092bd0843371c83c5293d5d7e73f19d Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Mon, 2 Mar 2026 14:50:59 -0600 Subject: [PATCH 5/5] Update src/MSBuild.UnitTests/MSBuildServer_Tests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/MSBuild.UnitTests/MSBuildServer_Tests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs index 5c38a41f3a0..6272a874389 100644 --- a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs +++ b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs @@ -191,7 +191,7 @@ public void BuildsWhileBuildIsRunningOnServer() string? dir = Path.GetDirectoryName(markerFile.Path); // mre must be declared before watcher so that it is disposed after watcher. - // Reversing this order would allow late FileSystemWatcher callbacks to call + // Reversing this order would allow late FileSystemWatcher callbacks to call // mre.Set() on a disposed ManualResetEvent, causing an ObjectDisposedException. using ManualResetEvent mre = new ManualResetEvent(false); using var watcher = new System.IO.FileSystemWatcher(dir!);