Skip to content

Commit bdfc86b

Browse files
committed
Fix #346: GetVersionDetails failing due to empty environment variable
This change fixes an issue caused by a recent change in the VS Code extension which wiped out all of the environment variables in the process. That particular issue has now been fixed but it's still good to guard against this problem in the future. This change adds a null check to ensure that we don't throw a NullReferenceException in future occurrences of the issue.
1 parent 003fc2b commit bdfc86b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/PowerShellEditorServices/Session/PowerShellVersionDetails.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ public static PowerShellVersionDetails GetVersionDetails(Runspace runspace)
134134
}
135135

136136
var arch = PowerShellContext.ExecuteScriptAndGetItem<string>("$env:PROCESSOR_ARCHITECTURE", runspace);
137-
if (string.Equals(arch, "AMD64", StringComparison.CurrentCultureIgnoreCase))
137+
if (arch != null)
138138
{
139-
architecture = PowerShellProcessArchitecture.X64;
140-
}
141-
else if (string.Equals(arch, "x86", StringComparison.CurrentCultureIgnoreCase))
142-
{
143-
architecture = PowerShellProcessArchitecture.X86;
139+
if (string.Equals(arch, "AMD64", StringComparison.CurrentCultureIgnoreCase))
140+
{
141+
architecture = PowerShellProcessArchitecture.X64;
142+
}
143+
else if (string.Equals(arch, "x86", StringComparison.CurrentCultureIgnoreCase))
144+
{
145+
architecture = PowerShellProcessArchitecture.X86;
146+
}
144147
}
145148
}
146149
}

0 commit comments

Comments
 (0)