From fd5b76691505d53f3e934f8502629c006539e82c Mon Sep 17 00:00:00 2001 From: Adam Anderson Date: Wed, 2 Aug 2023 17:24:39 -0400 Subject: [PATCH] Fix PlatformNotSupportedException thrown on Android in ConsoleTitler (#2390) * Remove Immutable packages reference from Forms sample * Catch PlatformNotSupportedException when checking if console output is redirected in ConsoleTitler --- .../BenchmarkDotNet.Samples.Forms.csproj | 1 - src/BenchmarkDotNet/Running/ConsoleTitler.cs | 13 ++++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/samples/BenchmarkDotNet.Samples.Forms/BenchmarkDotNet.Samples.Forms.csproj b/samples/BenchmarkDotNet.Samples.Forms/BenchmarkDotNet.Samples.Forms.csproj index ddec326433..38821b022a 100644 --- a/samples/BenchmarkDotNet.Samples.Forms/BenchmarkDotNet.Samples.Forms.csproj +++ b/samples/BenchmarkDotNet.Samples.Forms/BenchmarkDotNet.Samples.Forms.csproj @@ -10,7 +10,6 @@ - diff --git a/src/BenchmarkDotNet/Running/ConsoleTitler.cs b/src/BenchmarkDotNet/Running/ConsoleTitler.cs index 7983776e3c..9f8e21a1fe 100644 --- a/src/BenchmarkDotNet/Running/ConsoleTitler.cs +++ b/src/BenchmarkDotNet/Running/ConsoleTitler.cs @@ -20,10 +20,17 @@ internal class ConsoleTitler : IDisposable public ConsoleTitler(string initialTitle) { - // Return without enabling if Console output is redirected. - if (Console.IsOutputRedirected) + try + { + // Return without enabling if Console output is redirected. + if (Console.IsOutputRedirected) + { + return; + } + } + catch (PlatformNotSupportedException) { - return; + // Ignore the exception. Some platforms do not support Console.IsOutputRedirected. } try