Skip to content

Commit 8701ec1

Browse files
committed
Fix NullReferenceException in CommandHelpers
This change fixes a NullReferenceException which appears in CommandHelpers.GetCommandSynopsis when help can't be loaded for a given command.
1 parent 9df1b0f commit 8701ec1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/PowerShellEditorServices/Language/CommandHelpers.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ public static string GetCommandSynopsis(
6060
helpObject = powerShell.Invoke<PSObject>().FirstOrDefault();
6161
}
6262

63-
// Extract the synopsis string from the object
64-
synopsisString =
65-
(string)helpObject.Properties["synopsis"].Value ??
66-
string.Empty;
67-
68-
// Ignore the placeholder value for this field
69-
if (string.Equals(synopsisString, "SHORT DESCRIPTION", System.StringComparison.InvariantCultureIgnoreCase))
63+
if (helpObject != null)
7064
{
71-
synopsisString = string.Empty;
65+
// Extract the synopsis string from the object
66+
synopsisString =
67+
(string)helpObject.Properties["synopsis"].Value ??
68+
string.Empty;
69+
70+
// Ignore the placeholder value for this field
71+
if (string.Equals(synopsisString, "SHORT DESCRIPTION", System.StringComparison.InvariantCultureIgnoreCase))
72+
{
73+
synopsisString = string.Empty;
74+
}
7275
}
7376

7477
return synopsisString;

0 commit comments

Comments
 (0)