8000 Give error instead of crashing if WSMan client lib not available (#4387) · PowerShell/PowerShell@cf9f8c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf9f8c8

Browse files
SteveL-MSFTdaxian-dbw
authored andcommitted
Give error instead of crashing if WSMan client lib not available (#4387)
1 parent fa8b900 commit cf9f8c8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2597,7 +2597,15 @@ internal WSManAPIDataCommon()
25972597
#endif
25982598

25992599
_handle = IntPtr.Zero;
2600-
ErrorCode = WSManNativeApi.WSManInitialize(WSManNativeApi.WSMAN_FLAG_REQUESTED_API_VERSION_1_1, ref _handle);
2600+
2601+
try
2602+
{
2603+
ErrorCode = WSManNativeApi.WSManInitialize(WSManNativeApi.WSMAN_FLAG_REQUESTED_API_VERSION_1_1, ref _handle);
2604+
}
2605+
catch (DllNotFoundException)
2606+
{
2607+
throw new PSRemotingTransportException(RemotingErrorIdStrings.WSManClientDllNotAvailable);
2608+
}
26012609

26022610
// input / output streams common to all connections
26032611
_inputStreamSet = new WSManNativeApi.WSManStreamIDSet_ManToUn(

src/System.Management.Automation/resources/RemotingErrorIdStrings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,10 @@ All WinRM sessions connected to Windows PowerShell session configurations, such
16361636
<data name="InvalidRoleCapabilityFileExtension" xml:space="preserve">
16371637
<value>The provided role capability file {0} does not have the required .psrc extension.</value>
16381638
</data>
1639-
<data name="SSHAbruptlyTerminated" >
1639+
<data name="SSHAbruptlyTerminated" xml:space="preserve">
16401640
<value>The SSH transport process has abruptly terminated causing this remote session to break.</value>
16411641
</data>
1642+
<data name="WSManClientDllNotAvailable" xml:space="preserve">
1643+
<value>This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.</value>
1644+
</data>
16421645
</root>

0 commit comments

Comments
 (0)
0