Skip to content
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

Win7 OSArchitecture crash workaround #808

Merged
merged 5 commits into from
Dec 8, 2018
Merged
Changes from 2 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
30 changes: 27 additions & 3 deletions src/PowerShellEditorServices.Host/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public void StartLogging(string logFilePath, LogLevel logLevel)

string osVersion = RuntimeInformation.OSDescription;

string osArch = GetOSArchitecture();

string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? "<unspecified>";

string logHeader = $@"
Expand All @@ -164,12 +166,12 @@ public void StartLogging(string logFilePath, LogLevel logLevel)
Name: {this.hostDetails.Name}
Version: {this.hostDetails.Version}
ProfileId: {this.hostDetails.ProfileId}
Arch: {RuntimeInformation.OSArchitecture}
Arch: {osArch}

Operating system details:

Version: {osVersion}
Arch: {RuntimeInformation.OSArchitecture}
Arch: {osArch}

Build information:

Expand Down Expand Up @@ -245,7 +247,7 @@ await this.editorSession.PowerShellContext.ImportCommandsModule(
// gets initialized when that is done earlier than LanguageServer.Initialize
foreach (string module in this.additionalModules)
{
var command =
var command =
new System.Management.Automation.PSCommand()
.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
.AddParameter("Name", module);
Expand Down Expand Up @@ -493,6 +495,28 @@ private IServerListener CreateServiceListener(MessageProtocolType protocol, Edit
}
}

/// <summary>
/// Gets the OSArchitecture for logging. Cannot use System.Runtime.InteropServices.RuntimeInformation.OSArchitecture
/// directly, since this tries to load API set DLLs in win7 and crashes.
///
/// <returns></returns>
private string GetOSArchitecture()
{
#if !CoreCLR
// If on win7 (version 6.1.x), avoid System.Runtime.InteropServices.RuntimeInformation
if (Environment.OSVersion.Platform.Equals("Win32NT") && Environment.OSVersion.Version < new Version(6, 2))
{
if (Environment.Is64BitProcess)
{
return "X64";
}

return "X86";
}
#endif
return RuntimeInformation.OSArchitecture.ToString();
}

#endregion
}
}