From bd279ddb5281efd9c5fa0dd158c45c09f7c9ee58 Mon Sep 17 00:00:00 2001 From: Manuel Moraga Date: Mon, 14 Dec 2020 14:41:19 +0100 Subject: [PATCH] Fixes PlatformNotSupported on Xamarin.Mac modern. On Xamarin.Mac `Console.IsOutputRedirected` throws a `PlatformNotSupportedException`. This PR moves that line to within the try-catch-block so it can be safely ignored. --- src/CommandLine/ParserSettings.cs | 7 +++---- src/CommandLine/Text/HelpText.cs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/CommandLine/ParserSettings.cs b/src/CommandLine/ParserSettings.cs index 07c10c4c..bc523deb 100644 --- a/src/CommandLine/ParserSettings.cs +++ b/src/CommandLine/ParserSettings.cs @@ -41,13 +41,12 @@ public ParserSettings() private int GetWindowWidth() { - -#if !NET40 - if (Console.IsOutputRedirected) return DefaultMaximumLength; -#endif var width = 1; try { +#if !NET40 + if (Console.IsOutputRedirected) return DefaultMaximumLength; +#endif width = Console.WindowWidth; if (width < 1) { diff --git a/src/CommandLine/Text/HelpText.cs b/src/CommandLine/Text/HelpText.cs index f5e9a7b9..9e96dbc6 100644 --- a/src/CommandLine/Text/HelpText.cs +++ b/src/CommandLine/Text/HelpText.cs @@ -191,7 +191,7 @@ public HelpText(SentenceBuilder sentenceBuilder, string heading, string copyrigh maximumDisplayWidth = DefaultMaximumLength; } } - catch (IOException) + catch (Exception e) when ( e is IOException || e is PlatformNotSupportedException) { maximumDisplayWidth = DefaultMaximumLength; }