File tree 1 file changed +15
-4
lines changed
src/PowerShellEditorServices/Services/PowerShellContext/Session
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -89,21 +89,32 @@ internal static bool TryGetPSReadLineProxy(
89
89
{
90
90
readLineProxy = null ;
91
91
logger . LogTrace ( "Attempting to load PSReadLine" ) ;
92
- Console . WriteLine ( $ "Module path is { _psReadLineTestModulePath } ") ;
93
92
using ( var pwsh = PowerShell . Create ( ) )
94
93
{
95
94
pwsh . Runspace = runspace ;
96
95
pwsh . AddCommand ( "Microsoft.PowerShell.Core\\ Import-Module" )
97
96
. AddParameter ( "Name" , testing ? _psReadLineTestModulePath : _psReadLineModulePath )
98
97
. Invoke ( ) ;
99
98
99
+ if ( pwsh . HadErrors )
100
+ {
101
+ logger . LogWarning ( "PSConsoleReadline type not found: {Reason}" , pwsh . Streams . Error [ 0 ] . ToString ( ) ) ;
102
+ return false ;
103
+ }
104
+
100
105
var psReadLineType = Type . GetType ( "Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2" ) ;
101
106
102
107
if ( psReadLineType == null )
103
108
{
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
+ }
107
118
}
108
119
109
120
try
You can’t perform that action at this time.
0 commit comments