Skip to content

Fix startup assembly version loading issue in PS6 #1349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,20 @@ private async Task CreateEditorServicesAndRunUntilShutdown()
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
}

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

Task debugServerStart = null;
if (creatingDebugServer)
{
#pragma warning disable CS4014
// We don't need to wait for this to start, since we instead wait for it to complete later
StartDebugServer(debugServerCreation);
#pragma warning restore CS4014
debugServerStart = StartDebugServer(debugServerCreation);
}

await languageServerStart.ConfigureAwait(false);
if (debugServerStart != null)
{
await debugServerStart.ConfigureAwait(false);
}
await languageServer.WaitForShutdown().ConfigureAwait(false);
}
finally
Expand Down Expand Up @@ -165,10 +166,7 @@ private async Task StartDebugServer(Task<PsesDebugServer> debugServerCreation)

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

#pragma warning disable CS4014
// No need to await, since we just want to kick it off
debugServer.StartAsync();
#pragma warning restore CS4014
await debugServer.StartAsync().ConfigureAwait(false);
}

private Task RestartDebugServerAsync(PsesDebugServer debugServer, bool usePSReadLine)
Expand Down
20 changes: 16 additions & 4 deletions src/PowerShellEditorServices.Hosting/Internal/PsesLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ protected override Assembly Load(AssemblyName assemblyName)
// we must restrict the code in here to only use core types,
// otherwise we may depend on assembly that we are trying to load and cause a StackOverflowException

// If we find the required assembly in $PSHOME, let another mechanism load the assembly
string psHomeAsmPath = Path.Join(s_psHome, $"{assemblyName.Name}.dll");

if (File.Exists(psHomeAsmPath))
if (IsSatisfyingAssembly(assemblyName, psHomeAsmPath))
{
return null;
}

string asmPath = Path.Join(_dependencyDirPath, $"{assemblyName.Name}.dll");

if (File.Exists(asmPath))
if (IsSatisfyingAssembly(assemblyName, asmPath))
{
return LoadFromAssemblyPath(asmPath);
}
Expand Down Expand Up @@ -74,5 +73,18 @@ private void TrySetName(string name)
// Do nothing -- we did our best
}
}

private static bool IsSatisfyingAssembly(AssemblyName requiredAssemblyName, string assemblyPath)
{
if (!File.Exists(assemblyPath))
{
return false;
}

AssemblyName asmToLoadName = AssemblyName.GetAssemblyName(assemblyPath);

return string.Equals(asmToLoadName.Name, requiredAssemblyName.Name, StringComparison.OrdinalIgnoreCase)
&& asmToLoadName.Version >= requiredAssemblyName.Version;
}
}
}