Skip to content

Commit eafe88b

Browse files
committed
remove try catch for auomatic variable
1 parent 536b1ed commit eafe88b

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

src/code/Utils.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,17 +1207,9 @@ private static void GetStandardPlatformPaths(
12071207
out string localUserDir,
12081208
out string allUsersDir)
12091209
{
1210-
// Get PowerShell engine version from $PSVersionTable.PSVersion
1211-
Version psVersion = new Version(5, 1);
1212-
try
1213-
{
1214-
dynamic psVersionObj = (psCmdlet.SessionState.PSVariable.GetValue("PSVersionTable") as Hashtable)?["PSVersion"];
1215-
if (psVersionObj != null) psVersion = new Version((int)psVersionObj.Major, (int)psVersionObj.Minor);
1216-
}
1217-
catch {
1218-
// Fallback if dynamic access fails
1219-
psCmdlet.WriteWarning("Unable to determine PowerShell version from $PSVersionTable");
1220-
}
1210+
// Get PowerShell engine version from $PSVersionTable.PSVersion (automatic variable, always available)
1211+
dynamic psVersionObj = (psCmdlet.SessionState.PSVariable.GetValue("PSVersionTable") as Hashtable)["PSVersion"];
1212+
Version psVersion = new Version((int)psVersionObj.Major, (int)psVersionObj.Minor);
12211213

12221214
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
12231215
{

0 commit comments

Comments
 (0)