From cf9f8c8574e523ae3fe495033902edef75ee602a Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 31 Jul 2017 16:26:24 -0700 Subject: [PATCH] Give error instead of crashing if WSMan client lib not available (#4387) --- .../engine/remoting/fanin/WSManTransportManager.cs | 10 +++++++++- .../resources/RemotingErrorIdStrings.resx | 5 ++++- 2 files changed, 13 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 2bf8b842c0..7d1d08bc26 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs @@ -2597,7 +2597,15 @@ namespace System.Management.Automation.Remoting.Client #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(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 7b21c4be9b..5f9f5a98ed 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. + + This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system. +