Skip to content
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
6 changes: 2 additions & 4 deletions src/PowerShellEditorServices/Session/PowerShellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ namespace Microsoft.PowerShell.EditorServices
/// </summary>
public class PowerShellContext : IDisposable, IHostSupportsInteractiveSession
{
private const string DotNetFrameworkDescription = ".NET Framework";

private static readonly Action<Runspace, ApartmentState> s_runspaceApartmentStateSetter;

static PowerShellContext()
{
// PowerShell ApartmentState APIs aren't available in PSStandard, so we need to use reflection
if (RuntimeInformation.FrameworkDescription.Equals(DotNetFrameworkDescription))
if (!Utils.IsNetCore)
{
MethodInfo setterInfo = typeof(Runspace).GetProperty("ApartmentState").GetSetMethod();
Delegate setter = Delegate.CreateDelegate(typeof(Action<Runspace, ApartmentState>), firstArgument: null, method: setterInfo);
Expand Down Expand Up @@ -195,7 +193,7 @@ public static Runspace CreateRunspace(PSHost psHost)

// Windows PowerShell must be hosted in STA mode
// This must be set on the runspace *before* it is opened
if (RuntimeInformation.FrameworkDescription.Equals(DotNetFrameworkDescription))
if (s_runspaceApartmentStateSetter != null)
{
s_runspaceApartmentStateSetter(runspace, ApartmentState.STA);
}
Expand Down
5 changes: 5 additions & 0 deletions src/PowerShellEditorServices/Utility/ExecutionTimer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
Expand Down
5 changes: 5 additions & 0 deletions src/PowerShellEditorServices/Utility/Logging.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System;
using System.Collections.Generic;
using Serilog;
Expand Down
5 changes: 5 additions & 0 deletions src/PowerShellEditorServices/Utility/PsesLogger.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down
21 changes: 21 additions & 0 deletions src/PowerShellEditorServices/Utility/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System;
using System.Runtime.InteropServices;

namespace Microsoft.PowerShell.EditorServices
{
/// <summary>
/// General purpose common utilities to prevent reimplementation.
/// </summary>
internal static class Utils
{
/// <summary>
/// True if we are running on .NET Core, false otherwise.
/// </summary>
public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal);
}
}