Skip to content

Commit b24b0b5

Browse files
Use runspace to acquire version to avoid CLM issues
1 parent d209bd2 commit b24b0b5

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/code/InternalHooks.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ public static void SetTestHook(string property, object value)
2222
var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
2323
fieldInfo?.SetValue(null, value);
2424
}
25+
26+
public static string GetUserString()
27+
{
28+
return Microsoft.PowerShell.PSResourceGet.Cmdlets.UserAgentInfo.UserAgentString();
29+
}
2530
}
26-
}
31+
}

src/code/ServerFactory.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ internal static class UserAgentInfo
1212
{
1313
static UserAgentInfo()
1414
{
15-
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
16-
{
17-
_psVersion = ps.AddScript("$PSVersionTable").Invoke<Hashtable>()[0]["PSVersion"].ToString();
18-
}
19-
15+
_psVersion = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Version.ToString();
2016
_psResourceGetVersion = typeof(UserAgentInfo).Assembly.GetName().Version.ToString();
2117
_distributionChannel = System.Environment.GetEnvironmentVariable("POWERSHELL_DISTRIBUTION_CHANNEL") ?? "unknown";
2218
}

0 commit comments

Comments
 (0)