Skip to content

Commit 02d21f7

Browse files
authored
Fix faulty netfx check (#911)
* Fix faulty netfx check
1 parent ffd0ef7 commit 02d21f7

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

src/PowerShellEditorServices/Session/PowerShellContext.cs

+2-4
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

+5
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

+5
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

+5
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Microsoft.PowerShell.EditorServices
10+
{
11+
/// <summary>
12+
/// General purpose common utilities to prevent reimplementation.
13+
/// </summary>
14+
internal static class Utils
15+
{
16+
/// <summary>
17+
/// True if we are running on .NET Core, false otherwise.
18+
/// </summary>
19+
public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal);
20+
}
21+
}

0 commit comments

Comments
 (0)