From e8e5afd97c37a3fc829752db16798f1af7816747 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:22:23 +0000 Subject: [PATCH 1/3] Initial plan From 7564073119caff83901f2ccb333e4664b24353eb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:34:22 +0000 Subject: [PATCH 2/3] Fix test failure from background logging after xUnit test disposal Add try-catch in XunitLoggerProvider to gracefully handle exceptions when logging after xUnit's TestOutputHelper has been disposed. This prevents NullReferenceException when background work continues after test completion. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- tests/Common/Utils/XunitLoggerProvider.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/Common/Utils/XunitLoggerProvider.cs b/tests/Common/Utils/XunitLoggerProvider.cs index 9e77c1f39..5c7f65143 100644 --- a/tests/Common/Utils/XunitLoggerProvider.cs +++ b/tests/Common/Utils/XunitLoggerProvider.cs @@ -34,7 +34,15 @@ public void Log( sb.Append(exception.ToString()); } - output.WriteLine(sb.ToString()); + try + { + output.WriteLine(sb.ToString()); + } + catch + { + // Ignore exceptions from xUnit's TestOutputHelper when the test has already completed. + // Background work may continue logging after xUnit has disposed the test context. + } } public bool IsEnabled(LogLevel logLevel) => true; From 1b75ec0ef5733058c73f1d68abf2df9c1c2cc8fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:39:04 +0000 Subject: [PATCH 3/3] Catch specific exception types in XunitLoggerProvider Address code review feedback by catching specific exception types (InvalidOperationException and NullReferenceException) instead of catching all exceptions. This helps distinguish between expected disposal-related exceptions and genuine errors. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- tests/Common/Utils/XunitLoggerProvider.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Common/Utils/XunitLoggerProvider.cs b/tests/Common/Utils/XunitLoggerProvider.cs index 5c7f65143..2fb76fce1 100644 --- a/tests/Common/Utils/XunitLoggerProvider.cs +++ b/tests/Common/Utils/XunitLoggerProvider.cs @@ -38,11 +38,16 @@ public void Log( { output.WriteLine(sb.ToString()); } - catch + catch (InvalidOperationException) { // Ignore exceptions from xUnit's TestOutputHelper when the test has already completed. // Background work may continue logging after xUnit has disposed the test context. } + catch (NullReferenceException) + { + // xUnit v3 may throw NullReferenceException in TestOutputHelper.QueueTestOutput() + // when the internal queue has been torn down after test completion. + } } public bool IsEnabled(LogLevel logLevel) => true;