Skip to content
Closed
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 @@ -366,7 +366,6 @@ private object SafeCreateInstance(Type t, object[] args)
return result;
}

#if !CORECLR
private class ComCreateInfo
{
public Object objectCreated;
Expand Down Expand Up @@ -405,7 +404,6 @@ private void STAComCreateThreadProc(Object createstruct)
info.success = false;
}
}
#endif

private object CreateComObject()
{
Expand All @@ -428,13 +426,6 @@ private object CreateComObject()
//Check Error Code to see if Error is because of Com apartment Mismatch.
if (e.HResult == RPC_E_CHANGED_MODE)
{
#if CORECLR
ThrowTerminatingError(
new ErrorRecord(
new COMException(StringUtil.Format(NewObjectStrings.ApartmentNotSupported, e.Message), e),
"NoCOMClassIdentified",
ErrorCategory.ResourceUnavailable, null));
#else
createInfo = new ComCreateInfo();

Thread thread = new Thread(new ParameterizedThreadStart(STAComCreateThreadProc));
Expand All @@ -451,7 +442,6 @@ private object CreateComObject()
ThrowTerminatingError(
new ErrorRecord(createInfo.e, "NoCOMClassIdentified",
ErrorCategory.ResourceUnavailable, null));
#endif
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,8 @@ internal bool StaMode
}
else
{
#if CORECLR
// Nano doesn't support STA COM apartment, so on Nano powershell has to use MTA as the default.
return false;
#else
// Win8: 182409 PowerShell 3.0 should run in STA mode by default
return true;
#endif
}
}
}
Expand Down Expand Up @@ -736,7 +731,6 @@ private void ParseHelper(string[] args)
break;
}
}
#if !CORECLR // explicit setting of the ApartmentState Not supported on NanoServer
else if (MatchSwitch(switchKey, "sta", "s"))
{
if (_staMode.HasValue)
Expand All @@ -763,7 +757,6 @@ private void ParseHelper(string[] args)

_staMode = false;
}
#endif
else
{
// The first parameter we fail to recognize marks the beginning of the file string.
Expand Down
26 changes: 0 additions & 26 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,17 +1687,9 @@ private void DoCreateRunspace(string initialCommand, bool skipProfiles, bool sta

private void OpenConsoleRunspace(Runspace runspace, bool staMode)
{
// staMode will have following values:
// On FullPS: 'true'/'false' = default('true'=STA) + possibility of overload through cmdline parameter '-mta'
// On NanoPS: always 'false' = default('false'=MTA) + NO possibility of overload through cmdline parameter '-mta'
// ThreadOptions should match on FullPS and NanoPS for corresponding ApartmentStates.
if (staMode)
{
// we can't change ApartmentStates on CoreCLR
#if !CORECLR
runspace.ApartmentState = ApartmentState.STA;
#endif
runspace.ThreadOptions = PSThreadOptions.ReuseThread;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line supposed to be removed?

}

runspace.EngineActivityId = EtwActivity.GetActivityId();
Expand Down Expand Up @@ -2897,7 +2889,6 @@ private class ConsoleHostStartupException : Exception
base(message)
{
}
#if !CORECLR // ApplicationException & System.Runtime.Serialization.SerializationInfo are Not In CoreCLR
protected
ConsoleHostStartupException(
System.Runtime.Serialization.SerializationInfo info,
Expand All @@ -2906,7 +2897,6 @@ private class ConsoleHostStartupException : Exception
base(info, context)
{
}
#endif
internal
ConsoleHostStartupException(string message, Exception innerException)
:
Expand Down Expand Up @@ -2937,23 +2927,7 @@ private class ConsoleHostStartupException : Exception
private bool _isDisposed;
internal ConsoleHostUserInterface ui;

#if CORECLR
internal Lazy<TextReader> ConsoleIn { get; } = new Lazy<TextReader>(() => Console.In);
#else
internal Lazy<TextReader> ConsoleIn { get; } = new Lazy<TextReader>(() =>
{
// This is a workaround for a full clr issue that causes a hang when calling PowerShell from ruby.
// They use named pipes instead of anonymous pipes, and for some reason that triggers a hang
// reading from Console.In.
var inputHandle = ConsoleControl.NativeMethods.GetStdHandle(-10);
var s = new FileStream(new ConsoleHandle(inputHandle, false), FileAccess.Read);

uint codePage = (uint) ConsoleControl.NativeMethods.GetConsoleCP();
Encoding encoding = Encoding.GetEncoding((int) codePage);

return TextReader.Synchronized(new StreamReader(s, encoding, false));
});
#endif

private string _savedWindowTitle = "";
private Version _ver = PSVersionInfo.PSVersion;
Expand Down
4 changes: 0 additions & 4 deletions src/Microsoft.PowerShell.PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,6 @@ private static void Ignore(ConsoleKeyInfo? key = null, object arg = null)

private static void ExecuteOnSTAThread(Action action)
{
#if CORECLR
action();
#else
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
{
action();
Expand Down Expand Up @@ -743,7 +740,6 @@ private static void ExecuteOnSTAThread(Action action)
{
throw exception;
}
#endif
}

#region Miscellaneous bindable functions
Expand Down
29 changes: 0 additions & 29 deletions src/Microsoft.WSMan.Management/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Security;
#if !CORECLR
using System.ServiceProcess;
#endif

namespace Microsoft.WSMan.Management
{
Expand Down Expand Up @@ -113,11 +111,8 @@ string ICmdletProviderSupportsHelp.GetHelpMaml(string helpItemName, string path)

try
{
//XmlDocument in CoreCLR does not have file path parameter, use XmlReader
XmlReaderSettings readerSettings = new XmlReaderSettings();
#if !CORECLR
readerSettings.XmlResolver = null;
#endif
using (XmlReader reader = XmlReader.Create(helpFile, readerSettings))
{
document.Load(reader);
Expand Down Expand Up @@ -4463,10 +4458,6 @@ private void AssertError(string ErrorMessage, bool IsWSManError)
/// <returns></returns>
private bool IsWSManServiceRunning()
{
#if CORECLR
// TODO once s78 comes in undo this
return true;
#else
ServiceController svc = new ServiceController("WinRM");
if (svc != null)
{
Expand All @@ -4476,7 +4467,6 @@ private bool IsWSManServiceRunning()
}
}
return false;
#endif
}

/// <summary>
Expand Down Expand Up @@ -4515,8 +4505,6 @@ private bool IsPathLocalMachine(string host)
hostfound = true;
}

// Domain look up not available on CoreCLR?
#if !CORECLR
//Check is TestMac
if (!hostfound)
{
Expand Down Expand Up @@ -4559,7 +4547,6 @@ private bool IsPathLocalMachine(string host)
}
}
}
#endif
return hostfound;
}

Expand Down Expand Up @@ -4857,14 +4844,7 @@ private ArrayList ProcessPluginInitParamLevel(XmlDocument xmldoc)
if (attributecol[i].LocalName.Equals("Value", StringComparison.OrdinalIgnoreCase))
{
String ValueAsXML = attributecol[i].Value;
#if CORECLR
//SecurityElement.Escape() not supported on .NET Core, use WebUtility.HtmlEncode() to replace.
//During the encoding, single quote "\'" convert to "&#39;", then manually convert "&#39;" to "&apos;" since we are encode xml not html;
Value = System.Net.WebUtility.HtmlEncode(ValueAsXML);
Value = Value.Replace("&#39;", "&apos;");
#else
Value = SecurityElement.Escape(ValueAsXML);
#endif
}
}
objInitParam.Properties.Add(new PSNoteProperty(Name, Value));
Expand Down Expand Up @@ -5058,18 +5038,9 @@ private string GetStringFromSecureString(object propertyValue)

if (value != null)
{
#if !CORECLR
//coreCLR only supports marshal for unicode
IntPtr ptr = Marshal.SecureStringToBSTR(value);
passwordValueToAdd = Marshal.PtrToStringAuto(ptr);
Marshal.ZeroFreeBSTR(ptr);
#else
IntPtr ptr = SecureStringMarshal.SecureStringToCoTaskMemUnicode(value);
passwordValueToAdd = Marshal.PtrToStringUni(ptr);
Marshal.ZeroFreeCoTaskMemAnsi(ptr);
#endif


}

return passwordValueToAdd;
Expand Down
39 changes: 2 additions & 37 deletions src/Microsoft.WSMan.Management/CredSSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
using System.Globalization;
using System.Security;
using System.Threading;
#if CORECLR
using System.Xml.XPath;
#endif

using Dbg = System.Management.Automation;

Expand Down Expand Up @@ -335,15 +333,6 @@ private void DeleteDelegateSettings(string applicationname, RegistryKey rootKey,
/// </summary>
protected override void BeginProcessing()
{
#if !CORECLR
if (Environment.OSVersion.Version.Major < 6)
{
//OS is XP/Win2k3. Throw error.
WSManHelper helper = new WSManHelper(this);
string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
throw new InvalidOperationException(message);
}
#endif
//If not running elevated, then throw an "elevation required" error message.
WSManHelper.ThrowIfNotAdministrator();

Expand Down Expand Up @@ -453,14 +442,6 @@ protected override void BeginProcessing()
//If not running elevated, then throw an "elevation required" error message.
WSManHelper.ThrowIfNotAdministrator();
helper = new WSManHelper(this);
#if !CORECLR
if (Environment.OSVersion.Version.Major < 6)
{
//OS is XP/Win2k3. Throw error.
string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
throw new InvalidOperationException(message);
}
#endif

// DelegateComputer cannot be specified when Role is other than client
if ((delegatecomputer != null) && !Role.Equals(Client, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -725,23 +706,15 @@ private void UpdateGPORegistrySettings(string applicationname, string[] delegate
//open the registry key.If key is not present,create a new one
Credential_Delegation_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation, true);
if (Credential_Delegation_Key == null)
Credential_Delegation_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation
#if !CORECLR
, RegistryKeyPermissionCheck.ReadWriteSubTree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.Win32.RegistryKeyPermissionCheck is available in .NET Core. Maybe we should keep it?

#endif
);
Credential_Delegation_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation);

Credential_Delegation_Key.SetValue(helper.Key_Allow_Fresh_Credentials, 1, RegistryValueKind.DWord);
Credential_Delegation_Key.SetValue(helper.Key_Concatenate_Defaults_AllowFresh, 1, RegistryValueKind.DWord);

// add the delegate value
Allow_Fresh_Credential_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, true);
if (Allow_Fresh_Credential_Key == null)
Allow_Fresh_Credential_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials
#if !CORECLR
, RegistryKeyPermissionCheck.ReadWriteSubTree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

#endif
);
Allow_Fresh_Credential_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials);

if (Allow_Fresh_Credential_Key != null)
{
Expand Down Expand Up @@ -890,14 +863,6 @@ protected override void BeginProcessing()
WSManHelper.ThrowIfNotAdministrator();

helper = new WSManHelper(this);
#if !CORECLR
if (Environment.OSVersion.Version.Major < 6)
{
//OS is XP/Win2k3. Throw error.
string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the resource string CmdletNotAvailable can be removed?

throw new InvalidOperationException(message);
}
#endif

IWSManSession m_SessionObj = null;
try
Expand Down
Loading