diff --git a/tests/Common/Utils/XunitLoggerProvider.cs b/tests/Common/Utils/XunitLoggerProvider.cs index 9e77c1f39..2fb76fce1 100644 --- a/tests/Common/Utils/XunitLoggerProvider.cs +++ b/tests/Common/Utils/XunitLoggerProvider.cs @@ -34,7 +34,20 @@ public void Log( sb.Append(exception.ToString()); } - output.WriteLine(sb.ToString()); + try + { + output.WriteLine(sb.ToString()); + } + 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;