Skip to content

Commit 3909afb

Browse files
committed
Fix faulty netfx check
1 parent bfb4e8e commit 3909afb

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ namespace Microsoft.PowerShell.EditorServices
3434
/// </summary>
3535
public class PowerShellContext : IDisposable, IHostSupportsInteractiveSession
3636
{
37-
private const string DotNetFrameworkDescription = ".NET Framework";
38-
3937
private static readonly Action<Runspace, ApartmentState> s_runspaceApartmentStateSetter;
4038

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

196194
// Windows PowerShell must be hosted in STA mode
197195
// This must be set on the runspace *before* it is opened
198-
if (RuntimeInformation.FrameworkDescription.Equals(DotNetFrameworkDescription))
196+
if (s_runspaceApartmentStateSetter != null)
199197
{
200198
s_runspaceApartmentStateSetter(runspace, ApartmentState.STA);
201199
}

src/PowerShellEditorServices/Utility/ExecutionTimer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
16
using System;
27
using System.Diagnostics;
38
using System.Runtime.CompilerServices;

src/PowerShellEditorServices/Utility/Logging.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
16
using System;
27
using System.Collections.Generic;
38
using Serilog;

src/PowerShellEditorServices/Utility/PsesLogger.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
16
using System;
27
using System.Runtime.CompilerServices;
38
using System.Text;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System.Runtime.InteropServices;
7+
8+
namespace Microsoft.PowerShell.EditorServices
9+
{
10+
/// <summary>
11+
/// General purpose common utilities to prevent reimplementation.
12+
/// </summary>
13+
internal static class Utils
14+
{
15+
/// <summary>
16+
/// True if we are running on .NET Core, false otherwise.
17+
/// </summary>
18+
public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core");
19+
}
20+
}

0 commit comments

Comments
 (0)