Skip to content

Commit 9559b2f

Browse files
authored
Fix startup assembly version loading issue in PS6 (#1349)
1 parent 5463483 commit 9559b2f

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/PowerShellEditorServices.Hosting/Internal/EditorServicesRunner.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,20 @@ private async Task CreateEditorServicesAndRunUntilShutdown()
118118
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
119119
}
120120

121-
#pragma warning disable CS4014
122-
// We don't need to wait for this to start, since we instead wait for it to complete later
123-
languageServer.StartAsync();
124-
#pragma warning restore CS4014
121+
Task languageServerStart = languageServer.StartAsync();
125122

123+
Task debugServerStart = null;
126124
if (creatingDebugServer)
127125
{
128-
#pragma warning disable CS4014
129126
// We don't need to wait for this to start, since we instead wait for it to complete later
130-
StartDebugServer(debugServerCreation);
131-
#pragma warning restore CS4014
127+
debugServerStart = StartDebugServer(debugServerCreation);
132128
}
133129

130+
await languageServerStart.ConfigureAwait(false);
131+
if (debugServerStart != null)
132+
{
133+
await debugServerStart.ConfigureAwait(false);
134+
}
134135
await languageServer.WaitForShutdown().ConfigureAwait(false);
135136
}
136137
finally
@@ -165,10 +166,7 @@ private async Task StartDebugServer(Task<PsesDebugServer> debugServerCreation)
165166

166167
_logger.Log(PsesLogLevel.Diagnostic, "Starting debug server");
167168

168-
#pragma warning disable CS4014
169-
// No need to await, since we just want to kick it off
170-
debugServer.StartAsync();
171-
#pragma warning restore CS4014
169+
await debugServer.StartAsync().ConfigureAwait(false);
172170
}
173171

174172
private Task RestartDebugServerAsync(PsesDebugServer debugServer, bool usePSReadLine)

src/PowerShellEditorServices.Hosting/Internal/PsesLoadContext.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ protected override Assembly Load(AssemblyName assemblyName)
3737
// we must restrict the code in here to only use core types,
3838
// otherwise we may depend on assembly that we are trying to load and cause a StackOverflowException
3939

40+
// If we find the required assembly in $PSHOME, let another mechanism load the assembly
4041
string psHomeAsmPath = Path.Join(s_psHome, $"{assemblyName.Name}.dll");
41-
42-
if (File.Exists(psHomeAsmPath))
42+
if (IsSatisfyingAssembly(assemblyName, psHomeAsmPath))
4343
{
4444
return null;
4545
}
4646

4747
string asmPath = Path.Join(_dependencyDirPath, $"{assemblyName.Name}.dll");
48-
49-
if (File.Exists(asmPath))
48+
if (IsSatisfyingAssembly(assemblyName, asmPath))
5049
{
5150
return LoadFromAssemblyPath(asmPath);
5251
}
@@ -74,5 +73,18 @@ private void TrySetName(string name)
7473
// Do nothing -- we did our best
7574
}
7675
}
76+
77+
private static bool IsSatisfyingAssembly(AssemblyName requiredAssemblyName, string assemblyPath)
78+
{
79+
if (!File.Exists(assemblyPath))
80+
{
81+
return false;
82+
}
83+
84+
AssemblyName asmToLoadName = AssemblyName.GetAssemblyName(assemblyPath);
85+
86+
return string.Equals(asmToLoadName.Name, requiredAssemblyName.Name, StringComparison.OrdinalIgnoreCase)
87+
&& asmToLoadName.Version >= requiredAssemblyName.Version;
88+
}
7789
}
7890
}

0 commit comments

Comments
 (0)