From a8eb0f96784f7ae424af56eadbca2acf21575198 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 22 Mar 2018 00:36:43 -0700 Subject: [PATCH 1/2] fix GetVersionDetails error --- src/PowerShellEditorServices/Session/PowerShellContext.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Session/PowerShellContext.cs b/src/PowerShellEditorServices/Session/PowerShellContext.cs index 47c11272b..524583335 100644 --- a/src/PowerShellEditorServices/Session/PowerShellContext.cs +++ b/src/PowerShellEditorServices/Session/PowerShellContext.cs @@ -845,8 +845,12 @@ await this.ExecuteCommand( if (typeof(TResult) != typeof(PSObject)) { - return - results + return (results.FirstOrDefault() == null) + // Evaluates to null but couldn't put just null (needs to be a TResult) and also couldn't cast null to TResult + ? results + .OfType() + .FirstOrDefault() + : results .Select(pso => pso.BaseObject) .OfType() .FirstOrDefault(); From 6633d1fcf904a3cb1f0a5f6e2fbfebe8c30508ac Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 22 Mar 2018 13:40:24 -0700 Subject: [PATCH 2/2] cleaner conditional --- .../Session/PowerShellContext.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/PowerShellEditorServices/Session/PowerShellContext.cs b/src/PowerShellEditorServices/Session/PowerShellContext.cs index 524583335..f8d6e69a3 100644 --- a/src/PowerShellEditorServices/Session/PowerShellContext.cs +++ b/src/PowerShellEditorServices/Session/PowerShellContext.cs @@ -535,7 +535,7 @@ await Task.Factory.StartNew>( if (this.powerShell.HadErrors) { var strBld = new StringBuilder(1024); - strBld.AppendFormat("Execution of the following command(s) completed with errors:\r\n\r\n{0}\r\n", + strBld.AppendFormat("Execution of the following command(s) completed with errors:\r\n\r\n{0}\r\n", GetStringForPSCommand(psCommand)); int i = 1; @@ -838,19 +838,14 @@ await this.ExecuteCommand( Collection results = pipeline.Invoke(); - if (results.Count == 0) + if (results.Count == 0 || results.FirstOrDefault() == null) { return defaultValue; } if (typeof(TResult) != typeof(PSObject)) { - return (results.FirstOrDefault() == null) - // Evaluates to null but couldn't put just null (needs to be a TResult) and also couldn't cast null to TResult - ? results - .OfType() - .FirstOrDefault() - : results + return results .Select(pso => pso.BaseObject) .OfType() .FirstOrDefault();