Skip to content

Commit e615399

Browse files
dkattanandyleejordan
authored andcommitted
Search all assemblies for PSConsoleReadLine
1 parent d03f3d0 commit e615399

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,32 @@ internal static bool TryGetPSReadLineProxy(
8989
{
9090
readLineProxy = null;
9191
logger.LogTrace("Attempting to load PSReadLine");
92-
Console.WriteLine($"Module path is {_psReadLineTestModulePath}");
9392
using (var pwsh = PowerShell.Create())
9493
{
9594
pwsh.Runspace = runspace;
9695
pwsh.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
9796
.AddParameter("Name", testing ? _psReadLineTestModulePath : _psReadLineModulePath)
9897
.Invoke();
9998

99+
if (pwsh.HadErrors)
100+
{
101+
logger.LogWarning("PSConsoleReadline type not found: {Reason}", pwsh.Streams.Error[0].ToString());
102+
return false;
103+
}
104+
100105
var psReadLineType = Type.GetType("Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2");
101106

102107
if (psReadLineType == null)
103108
{
104-
logger.LogWarning("PSConsoleReadline type not found: {Reason}", pwsh.HadErrors ? pwsh.Streams.Error[0].ToString() : "<Unknown reason>");
105-
Console.WriteLine("Failed to GetType but no PowerShell error");
106-
return false;
109+
logger.LogTrace("PSConsoleReadline type not found using Type.GetType(), searching all loaded assemblies...");
110+
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
111+
var assemblies = allAssemblies.FirstOrDefault(a => a.FullName.Contains("Microsoft.PowerShell.PSReadLine2"));
112+
psReadLineType = assemblies?.ExportedTypes?.FirstOrDefault(a => a.FullName == "Microsoft.PowerShell.PSConsoleReadLine");
113+
if (psReadLineType == null)
114+
{
115+
logger.LogWarning("PSConsoleReadLine type not found anywhere!");
116+
return false;
117+
}
107118
}
108119

109120
try

0 commit comments

Comments
 (0)