From 672431e7dcbf5e0efa2c49fd23ae070bc5ba6093 Mon Sep 17 00:00:00 2001 From: SteveL-MSFT Date: Fri, 28 Jul 2017 16:08:47 -0700 Subject: [PATCH 1/2] Give better error when WSMan client library is not available instead of crashing --- .../engine/remoting/fanin/WSManTransportManager.cs | 11 ++++++++++- .../resources/RemotingErrorIdStrings.resx | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs index 2bf8b842c05..d459cdabc4d 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs @@ -2597,7 +2597,16 @@ internal WSManAPIDataCommon() #endif _handle = IntPtr.Zero; - ErrorCode = WSManNativeApi.WSManInitialize(WSManNativeApi.WSMAN_FLAG_REQUESTED_API_VERSION_1_1, ref _handle); + + try + { + ErrorCode = WSManNativeApi.WSManInitialize(WSManNativeApi.WSMAN_FLAG_REQUESTED_API_VERSION_1_1, ref _handle); + } + catch (DllNotFoundException) + { + throw new PSRemotingTransportException( + StringUtil.Format(RemotingErrorIdStrings.WSManClientDllNotAvailable)); + } // input / output streams common to all connections _inputStreamSet = new WSManNativeApi.WSManStreamIDSet_ManToUn( diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx index 7b21c4be9b1..87ddd2c745e 100644 --- a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx +++ b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx @@ -1636,7 +1636,10 @@ All WinRM sessions connected to Windows PowerShell session configurations, such The provided role capability file {0} does not have the required .psrc extension. - + The SSH transport process has abruptly terminated causing this remote session to break. + + WSMan client library is not installed + From 981bdb09faaae3259e8364e525b70cfbba18c42d Mon Sep 17 00:00:00 2001 From: SteveL-MSFT Date: Mon, 31 Jul 2017 12:42:43 -0700 Subject: [PATCH 2/2] updated error message based on feedback giving a bit more detail --- .../engine/remoting/fanin/WSManTransportManager.cs | 3 +-- .../resources/RemotingErrorIdStrings.resx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs index d459cdabc4d..7d1d08bc263 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs @@ -2604,8 +2604,7 @@ internal WSManAPIDataCommon() } catch (DllNotFoundException) { - throw new PSRemotingTransportException( - StringUtil.Format(RemotingErrorIdStrings.WSManClientDllNotAvailable)); + throw new PSRemotingTransportException(RemotingErrorIdStrings.WSManClientDllNotAvailable); } // input / output streams common to all connections diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx index 87ddd2c745e..5f9f5a98ed5 100644 --- a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx +++ b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx @@ -1640,6 +1640,6 @@ All WinRM sessions connected to Windows PowerShell session configurations, such The SSH transport process has abruptly terminated causing this remote session to break. - WSMan client library is not installed + This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.