From 9cf32d584b9e7c1bfc99bbfc31b654969d70505f Mon Sep 17 00:00:00 2001 From: "Steve Lee [MSFT]" Date: Tue, 15 Aug 2017 02:26:01 -0700 Subject: [PATCH 1/4] [Feature] add support for -sta/-mta in powershell.exe enable ApartmentState support overall some FullCLR code cleanup --- .../commands/utility/new-object.cs | 10 --- .../host/msh/CommandLineParameterParser.cs | 7 -- .../host/msh/ConsoleHost.cs | 26 ------- .../ReadLine.cs | 4 -- .../CoreCLR/CorePsStub.cs | 20 ------ .../engine/InitialSessionState.cs | 5 -- .../engine/hostifaces/Connection.cs | 9 +-- .../engine/hostifaces/ConnectionBase.cs | 15 +---- .../engine/hostifaces/LocalConnection.cs | 8 --- .../engine/hostifaces/LocalPipeline.cs | 23 +------ .../engine/hostifaces/PowerShell.cs | 14 ---- .../engine/hostifaces/RunspacePool.cs | 2 - .../engine/hostifaces/RunspacePoolInternal.cs | 7 -- .../engine/remoting/client/remoterunspace.cs | 2 - .../remoting/commands/CustomShellCommands.cs | 8 --- .../remoting/common/RunspaceConnectionInfo.cs | 11 --- .../common/WireDataFormat/EncodeAndDecode.cs | 18 +---- .../fanin/InitialSessionStateProvider.cs | 9 --- .../remoting/server/ServerPowerShellDriver.cs | 67 ------------------- .../server/ServerRunspacePoolDriver.cs | 66 ------------------ .../server/ServerSteppablePipelineDriver.cs | 35 ---------- .../remoting/server/serverremotesession.cs | 4 -- test/powershell/Host/ConsoleHost.Tests.ps1 | 12 ++++ 23 files changed, 17 insertions(+), 365 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs index 5c3f136f2bb..3d29d143ce7 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs @@ -366,7 +366,6 @@ private object SafeCreateInstance(Type t, object[] args) return result; } -#if !CORECLR private class ComCreateInfo { public Object objectCreated; @@ -405,7 +404,6 @@ private void STAComCreateThreadProc(Object createstruct) info.success = false; } } -#endif private object CreateComObject() { @@ -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)); @@ -451,7 +442,6 @@ private object CreateComObject() ThrowTerminatingError( new ErrorRecord(createInfo.e, "NoCOMClassIdentified", ErrorCategory.ResourceUnavailable, null)); -#endif } else { diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index 0bfb719e7be..b9dc3c7e69c 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -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 } } } @@ -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) @@ -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. diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 84e9cf33845..34acff88f02 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -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; } runspace.EngineActivityId = EtwActivity.GetActivityId(); @@ -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, @@ -2906,7 +2897,6 @@ private class ConsoleHostStartupException : Exception base(info, context) { } -#endif internal ConsoleHostStartupException(string message, Exception innerException) : @@ -2937,23 +2927,7 @@ private class ConsoleHostStartupException : Exception private bool _isDisposed; internal ConsoleHostUserInterface ui; -#if CORECLR internal Lazy ConsoleIn { get; } = new Lazy(() => Console.In); -#else - internal Lazy ConsoleIn { get; } = new Lazy(() => - { - // 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; diff --git a/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs b/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs index 0282d77841f..052c654260b 100644 --- a/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs +++ b/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs @@ -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(); @@ -743,7 +740,6 @@ private static void ExecuteOnSTAThread(Action action) { throw exception; } -#endif } #region Miscellaneous bindable functions diff --git a/src/System.Management.Automation/CoreCLR/CorePsStub.cs b/src/System.Management.Automation/CoreCLR/CorePsStub.cs index 0763a456fd7..ab3ce940434 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsStub.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsStub.cs @@ -133,26 +133,6 @@ public enum RollbackSeverity } #endregion PSTransaction - - #region ApartmentState - - internal enum ApartmentState - { - // - // Summary: - // The System.Threading.Thread will create and enter a single-threaded apartment. - STA = 0, - // - // Summary: - // The System.Threading.Thread will create and enter a multithreaded apartment. - MTA = 1, - // - // Summary: - // The System.Threading.Thread.ApartmentState property has not been set. - Unknown = 2 - } - - #endregion ApartmentState } namespace System.Management.Automation.Internal diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 3bac5a59061..b45d8d06ebc 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -2100,9 +2100,7 @@ public InitialSessionState Clone() ss.UseFullLanguageModeInDebugger = this.UseFullLanguageModeInDebugger; ss.ThreadOptions = this.ThreadOptions; ss.ThrowOnRunspaceOpenError = this.ThrowOnRunspaceOpenError; -#if !CORECLR // No ApartmentState In CoreCLR ss.ApartmentState = this.ApartmentState; -#endif foreach (ModuleSpecification modSpec in this.ModuleSpecificationsToImport) { @@ -2247,14 +2245,11 @@ public Microsoft.PowerShell.ExecutionPolicy ExecutionPolicy /// public bool UseFullLanguageModeInDebugger { get; set; } = false; -#if !CORECLR // No ApartmentState In CoreCLR /// /// ApartmentState of the thread used to execute commands /// public ApartmentState ApartmentState { get; set; } = Runspace.DefaultApartmentState; -#endif - /// /// This property determines whether a new thread is create for each invocation of a command /// diff --git a/src/System.Management.Automation/engine/hostifaces/Connection.cs b/src/System.Management.Automation/engine/hostifaces/Connection.cs index 40973e81f6c..446f54abace 100644 --- a/src/System.Management.Automation/engine/hostifaces/Connection.cs +++ b/src/System.Management.Automation/engine/hostifaces/Connection.cs @@ -557,7 +557,6 @@ public static bool CanUseDefaultRunspace } } -#if !CORECLR // No ApartmentState In CoreCLR internal const ApartmentState DefaultApartmentState = ApartmentState.Unknown; /// @@ -587,7 +586,6 @@ public ApartmentState ApartmentState } } private ApartmentState apartmentState = Runspace.DefaultApartmentState; -#endif /// /// This property determines whether a new thread is create for each invocation @@ -650,12 +648,7 @@ public abstract RunspaceAvailability RunspaceAvailability /// /// RunspaceConfiguration information for this runspace. /// -#if CORECLR - internal -#else - public -#endif - abstract RunspaceConfiguration RunspaceConfiguration + internal abstract RunspaceConfiguration RunspaceConfiguration { get; } diff --git a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs index e32dfc6a289..8e8dead7f92 100644 --- a/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs +++ b/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs @@ -84,10 +84,7 @@ protected RunspaceBase(PSHost host, InitialSessionState initialSessionState) Host = host; InitialSessionState = initialSessionState.Clone(); this.ThreadOptions = initialSessionState.ThreadOptions; - -#if !CORECLR // No ApartmentState In CoreCLR this.ApartmentState = initialSessionState.ApartmentState; -#endif } /// @@ -131,10 +128,7 @@ protected RunspaceBase(PSHost host, InitialSessionState initialSessionState, boo InitialSessionState = initialSessionState.Clone(); } this.ThreadOptions = initialSessionState.ThreadOptions; - -#if !CORECLR // No ApartmentState In CoreCLR this.ApartmentState = initialSessionState.ApartmentState; -#endif } /// @@ -145,12 +139,7 @@ protected RunspaceBase(PSHost host, InitialSessionState initialSessionState, boo /// /// runspaceConfiguration information for this runspace /// -#if CORECLR - internal -#else - public -#endif - override RunspaceConfiguration RunspaceConfiguration { get; } + internal override RunspaceConfiguration RunspaceConfiguration { get; } /// /// runspaceConfiguration information for this runspace @@ -942,7 +931,6 @@ internal bool WaitForFinishofPipelines() waitHandles[i] = runningPipelines[i].PipelineFinishedEvent; } -#if !CORECLR // No ApartmentState.STA In CoreCLR // WaitAll for multiple handles on a STA (single-thread apartment) thread is not supported as WaitAll will prevent the message pump to run if (runningPipelines.Length > 1 && Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { @@ -962,7 +950,6 @@ internal bool WaitForFinishofPipelines() return waitAllIsDone.WaitOne(); } } -#endif return WaitHandle.WaitAll(waitHandles); } else diff --git a/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs b/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs index 550d55b5e56..ed03b980020 100644 --- a/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs +++ b/src/System.Management.Automation/engine/hostifaces/LocalConnection.cs @@ -165,15 +165,11 @@ public override PSThreadOptions ThreadOptions { if (this.RunspaceStateInfo.State != RunspaceState.BeforeOpen) { -#if CORECLR // No ApartmentState.STA Support In CoreCLR - bool allowed = value == PSThreadOptions.ReuseThread; -#else // if the runspace is already opened we only allow changing the options if // the apartment state is MTA and the new value is ReuseThread bool allowed = (this.ApartmentState == ApartmentState.MTA || this.ApartmentState == ApartmentState.Unknown) // Unknown is the same as MTA && value == PSThreadOptions.ReuseThread; -#endif if (!allowed) { @@ -798,11 +794,7 @@ internal PipelineThread GetPipelineThread() { if (_pipelineThread == null) { -#if CORECLR // No ApartmentState In CoreCLR - _pipelineThread = new PipelineThread(); -#else _pipelineThread = new PipelineThread(this.ApartmentState); -#endif } return _pipelineThread; diff --git a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs index 07050165e3b..59ccaa3b2d4 100644 --- a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs +++ b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs @@ -151,12 +151,6 @@ protected override void StartPipelineExecution() case PSThreadOptions.Default: case PSThreadOptions.UseNewThread: { -#if CORECLR - //Start execution of pipeline in another thread - // No ApartmentState/ThreadStackSize In CoreCLR - Thread invokeThread = new Thread(new ThreadStart(this.InvokeThreadProc)); - SetupInvokeThread(invokeThread, true); -#else //Start execution of pipeline in another thread // 2004/05/02-JonN Specify maxStack parameter Thread invokeThread = new Thread(new ThreadStart(this.InvokeThreadProc), MaxStack); @@ -177,7 +171,6 @@ protected override void StartPipelineExecution() { invokeThread.SetApartmentState(apartmentState); } -#endif invokeThread.Start(); break; @@ -247,7 +240,6 @@ private void SetupInvokeThread(Thread invokeThread, bool changeName) } } -#if !CORECLR /// /// Stack Reserve setting for pipeline threads /// @@ -255,7 +247,7 @@ internal static int MaxStack { get { - int i = ReadRegistryInt("PipelineMaxStackSizeMB", 10); + int i = ReadRegistryInt("PipelineMaxStackSizeMB", 10); // TODO: move to startupconfig if (i < 10) i = 10; // minimum 10MB else if (i > 100) @@ -294,7 +286,6 @@ internal static int ReadRegistryInt(string policyValueName, int defaultValue) int i = (int)temp; return i; } -#endif /// /// Helper method for asynchronous invoke @@ -675,13 +666,11 @@ private void InvokeThreadProc() SetPipelineState(PipelineState.Failed, ex); SetHadErrors(true); } -#if !CORECLR // No ThreadAbortException In CoreCLR catch (ThreadAbortException ex) { SetPipelineState(PipelineState.Failed, ex); SetHadErrors(true); } -#endif // 1021203-2005/05/09-JonN // HaltCommandException will cause the command // to stop, but not be reported as an error. @@ -1233,15 +1222,6 @@ internal class PipelineThread : IDisposable /// /// Creates the worker thread and waits for it to be ready /// -#if CORECLR - internal PipelineThread() - { - _worker = new Thread(WorkerProc); - _workItem = null; - _workItemReady = new AutoResetEvent(false); - _closed = false; - } -#else internal PipelineThread(ApartmentState apartmentState) { _worker = new Thread(WorkerProc, LocalPipeline.MaxStack); @@ -1254,7 +1234,6 @@ internal PipelineThread(ApartmentState apartmentState) _worker.SetApartmentState(apartmentState); } } -#endif /// /// Returns the worker thread diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 5db5e5171df..21596f9c56e 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -325,9 +325,7 @@ public sealed class PSInvocationSettings /// public PSInvocationSettings() { -#if !CORECLR // No ApartmentState In CoreCLR this.ApartmentState = ApartmentState.Unknown; -#endif _host = null; RemoteStreamOptions = 0; AddToHistory = false; @@ -336,13 +334,11 @@ public PSInvocationSettings() #endregion -#if !CORECLR // No ApartmentState In CoreCLR /// /// ApartmentState of the thread in which the command /// is executed. /// public ApartmentState ApartmentState { get; set; } -#endif /// /// Host to use with the Runspace when the command is @@ -4221,9 +4217,7 @@ private void CoreInvokeHelper(PSDataCollection input, P { if (null != pool) { -#if !CORECLR // No ApartmentState In CoreCLR VerifyThreadSettings(settings, pool.ApartmentState, pool.ThreadOptions, false); -#endif // getting the runspace asynchronously so that Stop can be supported from a different // thread. _worker.GetRunspaceAsyncResult = pool.BeginGetRunspace(null, null); @@ -4235,9 +4229,7 @@ private void CoreInvokeHelper(PSDataCollection input, P rsToUse = _rsConnection as Runspace; if (null != rsToUse) { -#if !CORECLR // No ApartmentState In CoreCLR VerifyThreadSettings(settings, rsToUse.ApartmentState, rsToUse.ThreadOptions, false); -#endif if (rsToUse.RunspaceStateInfo.State != RunspaceState.Opened) { string message = StringUtil.Format(PowerShellStrings.InvalidRunspaceState, RunspaceState.Opened, rsToUse.RunspaceStateInfo.State); @@ -4505,9 +4497,7 @@ private IAsyncResult CoreInvokeAsync(PSDataCollection i { if (null != pool) { -#if !CORECLR // No ApartmentState In CoreCLR VerifyThreadSettings(settings, pool.ApartmentState, pool.ThreadOptions, pool.IsRemote); -#endif pool.AssertPoolIsOpen(); // for executing in a remote runspace pool case @@ -4581,9 +4571,7 @@ private IAsyncResult CoreInvokeAsync(PSDataCollection i LocalRunspace rs = _rsConnection as LocalRunspace; if (null != rs) { -#if !CORECLR // No ApartmentState In CoreCLR VerifyThreadSettings(settings, rs.ApartmentState, rs.ThreadOptions, false); -#endif if (rs.RunspaceStateInfo.State != RunspaceState.Opened) { string message = StringUtil.Format(PowerShellStrings.InvalidRunspaceState, RunspaceState.Opened, rs.RunspaceStateInfo.State); @@ -4630,7 +4618,6 @@ private IAsyncResult CoreInvokeAsync(PSDataCollection i return _invokeAsyncResult; } -#if !CORECLR // No ApartmentState In CoreCLR /// /// Verifies the settings for ThreadOptions and ApartmentState /// @@ -4665,7 +4652,6 @@ private void VerifyThreadSettings(PSInvocationSettings settings, ApartmentState } } } -#endif /// /// diff --git a/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs b/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs index 78dc8d777d6..b103fb14fe9 100644 --- a/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs +++ b/src/System.Management.Automation/engine/hostifaces/RunspacePool.cs @@ -1265,7 +1265,6 @@ public PSThreadOptions ThreadOptions } } -#if !CORECLR // No ApartmentState In CoreCLR /// /// ApartmentState of the thread used to execute commands within this RunspacePool /// @@ -1292,7 +1291,6 @@ public ApartmentState ApartmentState _internalPool.ApartmentState = value; } } -#endif /// /// Gets Runspace asynchronously from the runspace pool. The caller diff --git a/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs b/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs index bd43333cde2..77fe6ad57bb 100644 --- a/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs +++ b/src/System.Management.Automation/engine/hostifaces/RunspacePoolInternal.cs @@ -143,10 +143,7 @@ public RunspacePoolInternal(int minRunspaces, _initialSessionState = initialSessionState.Clone(); this.host = host; ThreadOptions = initialSessionState.ThreadOptions; -#if !CORECLR - // No ApartmentState In CoreCLR this.ApartmentState = initialSessionState.ApartmentState; -#endif pool = new Stack(); runspaceRequestQueue = new Queue(); ultimateRequestQueue = new Queue(); @@ -872,7 +869,6 @@ public virtual void Dispose(bool disposing) /// internal PSThreadOptions ThreadOptions { get; set; } = PSThreadOptions.Default; -#if !CORECLR // No ApartmentState In CoreCLR /// /// The value of this property is propagated to all the Runspaces in this pool /// @@ -880,7 +876,6 @@ public virtual void Dispose(bool disposing) /// Any updates to the value of this property must be done before the RunspacePool is opened /// internal ApartmentState ApartmentState { get; set; } = Runspace.DefaultApartmentState; -#endif /// /// Gets Runspace asynchronously from the runspace pool. The caller @@ -1289,9 +1284,7 @@ protected Runspace CreateRunspace() } result.ThreadOptions = this.ThreadOptions == PSThreadOptions.Default ? PSThreadOptions.ReuseThread : this.ThreadOptions; -#if !CORECLR // No ApartmentState In CoreCLR result.ApartmentState = this.ApartmentState; -#endif this.PropagateApplicationPrivateData(result); diff --git a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs index 6499ec7cad7..692f517ba53 100644 --- a/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs +++ b/src/System.Management.Automation/engine/remoting/client/remoterunspace.cs @@ -554,9 +554,7 @@ public override void Open() try { RunspacePool.ThreadOptions = this.ThreadOptions; -#if !CORECLR // No ApartmentState In CoreCLR RunspacePool.ApartmentState = this.ApartmentState; -#endif RunspacePool.Open(); } catch (InvalidRunspacePoolStateException e) diff --git a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs index c28b7939ddf..6095c372cf7 100644 --- a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs +++ b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs @@ -1089,7 +1089,6 @@ private string ConstructPluginContent(out string srcConfigFilePath, out string d maxObjectSizeMB.Value, Environment.NewLine)); } -#if !CORECLR // No ApartmentState In CoreCLR if (threadAptState.HasValue) { initParameters.Append(string.Format(CultureInfo.InvariantCulture, @@ -1098,7 +1097,6 @@ private string ConstructPluginContent(out string srcConfigFilePath, out string d threadAptState.Value, Environment.NewLine)); } -#endif if (threadOptions.HasValue) { initParameters.Append(string.Format(CultureInfo.InvariantCulture, @@ -2135,7 +2133,6 @@ public PSCredential RunAsCredential internal PSCredential runAsCredential; internal bool isRunAsCredentialSpecified; -#if !CORECLR // No ApartmentState In CoreCLR /// /// ApartmentState of the Runspace created for the shell. /// @@ -2155,7 +2152,6 @@ public ApartmentState ThreadApartmentState set { threadAptState = value; } } internal Nullable threadAptState; -#endif /// /// ThreadOptions of the Runspace created for the shell. @@ -3286,9 +3282,7 @@ function Set-RunAsCredential{{ ConfigurationDataFromXML.MAXRCVDOBJSIZETOKEN, ConfigurationDataFromXML.MAXRCVDCMDSIZETOKEN, ConfigurationDataFromXML.THREADOPTIONSTOKEN, -#if !CORECLR // No ApartmentState In CoreCLR ConfigurationDataFromXML.THREADAPTSTATETOKEN, -#endif ConfigurationDataFromXML.PSVERSIONTOKEN, ConfigurationDataFromXML.MAXPSVERSIONTOKEN, ConfigurationDataFromXML.SESSIONCONFIGTOKEN, @@ -3954,12 +3948,10 @@ private PSObject ConstructPropertiesForUpdate() result.Properties.Add(new PSNoteProperty(ConfigurationDataFromXML.MAXRCVDOBJSIZETOKEN, input)); } -#if !CORECLR // No ApartmentState In CoreCLR if (threadAptState.HasValue) { result.Properties.Add(new PSNoteProperty(ConfigurationDataFromXML.THREADAPTSTATETOKEN, threadAptState.Value)); } -#endif if (threadOptions.HasValue) { diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs index e444e1e272f..7bb5b5e0318 100644 --- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs +++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs @@ -3300,16 +3300,6 @@ private void GetContainerPropertiesInternal() /// private void RunOnMTAThread(ThreadStart threadProc) { - // - // By default, non-OneCore PowerShell is launched with ApartmentState being STA. - // In this case, we need to create a separate thread, set its ApartmentState to MTA, - // and do the work. - // - // For OneCore PowerShell, its ApartmentState is always MTA. - // -#if CORECLR - threadProc(); -#else if (Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA) { threadProc(); @@ -3322,7 +3312,6 @@ private void RunOnMTAThread(ThreadStart threadProc) executionThread.Start(); executionThread.Join(); } -#endif } /// diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs index 5411dc2dba6..c365a03bd26 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs @@ -677,11 +677,7 @@ internal static RemoteDataObject GenerateCreateRunspacePool( dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.MinRunspaces, minRunspaces)); dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.MaxRunspaces, maxRunspaces)); dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.ThreadOptions, runspacePool.ThreadOptions)); -#if CORECLR // No ApartmentState In CoreCLR, default to MTA for outgoing objects - ApartmentState poolState = ApartmentState.MTA; -#else ApartmentState poolState = runspacePool.ApartmentState; -#endif dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.ApartmentState, poolState)); dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.ApplicationArguments, applicationArguments)); @@ -1112,12 +1108,7 @@ internal static RemoteDataObject GenerateCreatePowerShell(ClientRemotePowerShell { hostInfo = new HostInfo(null); hostInfo.UseRunspaceHost = true; - -#if CORECLR // No ApartmentState In CoreCLR, default to MTA for outgoing objects - ApartmentState passedApartmentState = ApartmentState.MTA; -#else ApartmentState passedApartmentState = rsPool.ApartmentState; -#endif dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.ApartmentState, passedApartmentState)); dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.RemoteStreamOptions, RemoteStreamOptions.AddInvocationInfo)); dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.AddToHistory, false)); @@ -1130,11 +1121,7 @@ internal static RemoteDataObject GenerateCreatePowerShell(ClientRemotePowerShell hostInfo.UseRunspaceHost = true; } -#if CORECLR // No ApartmentState In CoreCLR, default to MTA for outgoing objects - ApartmentState passedApartmentState = ApartmentState.MTA; -#else ApartmentState passedApartmentState = settings.ApartmentState; -#endif dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.ApartmentState, passedApartmentState)); dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.RemoteStreamOptions, settings.RemoteStreamOptions)); dataAsPSObject.Properties.Add(new PSNoteProperty(RemoteDataNameStrings.AddToHistory, settings.AddToHistory)); @@ -2341,7 +2328,6 @@ internal static bool GetIsNested(object data) return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.IsNested); } -#if !CORECLR // No ApartmentState In CoreCLR /// /// Gets the invocation settings information from the message /// @@ -2352,7 +2338,7 @@ internal static ApartmentState GetApartmentState(object data) PSObject dataAsPSObject = PSObject.AsPSObject(data); return GetPropertyValue(dataAsPSObject, RemoteDataNameStrings.ApartmentState); } -#endif + /// /// Gets the stream options from the message /// @@ -2401,7 +2387,7 @@ internal static RemoteSessionCapability GetSessionCapability(object data) // // So just return the CurrentTimeZone. -#if !CORECLR // TimeZone Not In CoreCLR +#if !CORECLR // TimeZone deprecated, need to change to TimeZoneInfo result.TimeZone = TimeZone.CurrentTimeZone; #endif } diff --git a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs index fc82d5c4f4a..b8cf30c59b5 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/InitialSessionStateProvider.cs @@ -44,9 +44,7 @@ internal class ConfigurationDataFromXML internal const string MAXRCVDCMDSIZETOKEN = "psmaximumreceiveddatasizepercommandmb"; internal const string MAXRCVDCMDSIZETOKEN_CamelCase = "PSMaximumReceivedDataSizePerCommandMB"; internal const string THREADOPTIONSTOKEN = "pssessionthreadoptions"; -#if !CORECLR // No ApartmentState In CoreCLR internal const string THREADAPTSTATETOKEN = "pssessionthreadapartmentstate"; -#endif internal const string SESSIONCONFIGTOKEN = "sessionconfigurationdata"; internal const string PSVERSIONTOKEN = "PSVersion"; internal const string MAXPSVERSIONTOKEN = "MaxPSVersion"; @@ -72,10 +70,7 @@ internal class ConfigurationDataFromXML internal Nullable MaxReceivedCommandSizeMB; // Used to set properties on the RunspacePool created for this shell. internal Nullable ShellThreadOptions; - -#if !CORECLR // No ApartmentState In CoreCLR internal Nullable ShellThreadApartmentState; -#endif internal PSSessionConfigurationData SessionConfigurationData; internal string ConfigFilePath; @@ -131,13 +126,11 @@ private void Update(string optionName, string optionValue) ShellThreadOptions = (PSThreadOptions)LanguagePrimitives.ConvertTo( optionValue, typeof(PSThreadOptions), CultureInfo.InvariantCulture); break; -#if !CORECLR // No ApartmentState In CoreCLR case THREADAPTSTATETOKEN: AssertValueNotAssigned(THREADAPTSTATETOKEN, ShellThreadApartmentState); ShellThreadApartmentState = (System.Threading.ApartmentState)LanguagePrimitives.ConvertTo( optionValue, typeof(System.Threading.ApartmentState), CultureInfo.InvariantCulture); break; -#endif case SESSIONCONFIGTOKEN: { AssertValueNotAssigned(SESSIONCONFIGTOKEN, SessionConfigurationData); @@ -252,9 +245,7 @@ internal static ConfigurationDataFromXML Create(string initializationParameters) readerSettings.IgnoreProcessingInstructions = true; readerSettings.MaxCharactersInDocument = 10000; readerSettings.ConformanceLevel = ConformanceLevel.Fragment; -#if !CORECLR // No XmlReaderSettings.XmlResolver in CoreCLR readerSettings.XmlResolver = null; -#endif using (XmlReader reader = XmlReader.Create(new StringReader(initializationParameters), readerSettings)) { diff --git a/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs b/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs index a21cea97117..6a6ede844ab 100644 --- a/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs +++ b/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs @@ -38,9 +38,7 @@ internal class ServerPowerShellDriver private bool _addToHistory; private ServerRemoteHost _remoteHost; // the server remote host instance // associated with this powershell -#if !CORECLR // No ApartmentState In CoreCLR private ApartmentState apartmentState; // apartment state for this powershell -#endif private IRSPDriverInvoke _psDriverInvoker; // Handles nested invocation of PS drivers. @@ -48,7 +46,6 @@ internal class ServerPowerShellDriver #region Constructors -#if !CORECLR /// /// Default constructor for creating ServerPowerShellDrivers /// @@ -78,66 +75,7 @@ internal ServerPowerShellDriver(PowerShell powershell, PowerShell extraPowerShel apartmentState, hostInfo, streamOptions, addToHistory, rsToUse, null) { } -#else - /// - /// Default constructor for creating ServerPowerShellDrivers - /// - /// decoded powershell object - /// extra pipeline to be run after completes - /// whether there is input for this powershell - /// the client powershell id - /// the client runspacepool id - /// runspace pool driver - /// which is creating this powershell driver - /// host info using which the host for - /// this powershell will be constructed - /// serialization options for the streams in this powershell - /// - /// true if the command is to be added to history list of the runspace. false, otherwise. - /// - /// - /// If not null, this Runspace will be used to invoke Powershell. - /// If null, the RunspacePool pointed by will be used. - /// - internal ServerPowerShellDriver(PowerShell powershell, PowerShell extraPowerShell, bool noInput, Guid clientPowerShellId, - Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, - HostInfo hostInfo, RemoteStreamOptions streamOptions, - bool addToHistory, Runspace rsToUse) - : this(powershell, extraPowerShell, noInput, clientPowerShellId, clientRunspacePoolId, runspacePoolDriver, - hostInfo, streamOptions, addToHistory, rsToUse, null) - { - } -#endif -#if CORECLR - /// - /// Default constructor for creating ServerPowerShellDrivers - /// - /// decoded powershell object - /// extra pipeline to be run after completes - /// whether there is input for this powershell - /// the client powershell id - /// the client runspacepool id - /// runspace pool driver - /// which is creating this powershell driver - /// host info using which the host for - /// this powershell will be constructed - /// serialization options for the streams in this powershell - /// - /// true if the command is to be added to history list of the runspace. false, otherwise. - /// - /// - /// If not null, this Runspace will be used to invoke Powershell. - /// If null, the RunspacePool pointed by will be used. - /// - /// - /// If not null, this is used as another source of output sent to the client. - /// - internal ServerPowerShellDriver(PowerShell powershell, PowerShell extraPowerShell, bool noInput, Guid clientPowerShellId, - Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, - HostInfo hostInfo, RemoteStreamOptions streamOptions, - bool addToHistory, Runspace rsToUse, PSDataCollection output) -#else /// /// Default constructor for creating ServerPowerShellDrivers /// @@ -166,14 +104,11 @@ internal ServerPowerShellDriver(PowerShell powershell, PowerShell extraPowerShel Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, ApartmentState apartmentState, HostInfo hostInfo, RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, PSDataCollection output) -#endif { InstanceId = clientPowerShellId; RunspacePoolId = clientRunspacePoolId; RemoteStreamOptions = streamOptions; -#if !CORECLR // No ApartmentState In CoreCLR this.apartmentState = apartmentState; -#endif LocalPowerShell = powershell; _extraPowerShell = extraPowerShell; _localPowerShellOutput = new PSDataCollection(); @@ -291,9 +226,7 @@ private PSInvocationSettings PrepInvoke(bool startMainPowerShell) } PSInvocationSettings settings = new PSInvocationSettings(); -#if !CORECLR // No ApartmentState In CoreCLR settings.ApartmentState = apartmentState; -#endif settings.Host = _remoteHost; // Flow the impersonation policy to pipeline execution thread diff --git a/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs b/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs index a262751b792..5f1642d4705 100644 --- a/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs +++ b/src/System.Management.Automation/engine/remoting/server/ServerRunspacePoolDriver.cs @@ -93,47 +93,6 @@ private Dictionary _associatedShells #region Constructors - -#if CORECLR // No ApartmentState In CoreCLR - /// - /// Creates the runspace pool driver - /// - /// client runspace pool id to associate - /// transport manager associated with this - /// runspace pool driver - /// maximum runspaces to open - /// minimum runspaces to open - /// threading options for the runspaces in the pool - /// host information about client side host - /// - /// Contains: - /// 1. Script to run after a RunspacePool/Runspace is created in this session. - /// For RunspacePool case, every newly created Runspace (in the pool) will run - /// this script. - /// 2. ThreadOptions for RunspacePool/Runspace - /// 3. ThreadApartment for RunspacePool/Runspace - /// - /// configuration of the runspace - /// application private data - /// True if the driver is being created by an administrator - /// server capability reported to the client during negotiation (not the actual capability) - /// Client PowerShell version. - /// Optional endpoint configuration name to create a pushed configured runspace. - internal ServerRunspacePoolDriver( - Guid clientRunspacePoolId, - int minRunspaces, - int maxRunspaces, - PSThreadOptions threadOptions, - HostInfo hostInfo, - InitialSessionState initialSessionState, - PSPrimitiveDictionary applicationPrivateData, - ConfigurationDataFromXML configData, - AbstractServerSessionTransportManager transportManager, - bool isAdministrator, - RemoteSessionCapability serverCapability, - Version psClientVersion, - string configurationName) -#else /// /// Creates the runspace pool driver /// @@ -174,7 +133,6 @@ internal ServerRunspacePoolDriver( RemoteSessionCapability serverCapability, Version psClientVersion, string configurationName) -#endif { Dbg.Assert(null != configData, "ConfigurationData cannot be null"); @@ -212,7 +170,6 @@ internal ServerRunspacePoolDriver( RunspacePool.ThreadOptions = threadOptions; } -#if !CORECLR // No ApartmentState In CoreCLR // Set Thread ApartmentState for this RunspacePool ApartmentState serverApartmentState = configData.ShellThreadApartmentState.HasValue ? configData.ShellThreadApartmentState.Value : Runspace.DefaultApartmentState; @@ -224,7 +181,6 @@ internal ServerRunspacePoolDriver( { RunspacePool.ApartmentState = apartmentState; } -#endif // If we have a runspace pool with a single runspace then we can run nested pipelines on // on it in a single pipeline invoke thread. @@ -575,9 +531,7 @@ private PSDataCollection InvokePowerShell(PowerShell powershell, Runsp Guid.Empty, this.InstanceId, this, -#if !CORECLR // No ApartmentState In CoreCLR args.Runspace.ApartmentState, -#endif hostInfo, RemoteStreamOptions.AddInvocationInfo, false, @@ -758,9 +712,7 @@ private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs< // invoked from within the driver HostInfo hostInfo = RemotingDecoder.GetHostInfo(data.Data); -#if !CORECLR // No ApartmentState In CoreCLR ApartmentState apartmentState = RemotingDecoder.GetApartmentState(data.Data); -#endif RemoteStreamOptions streamOptions = RemotingDecoder.GetRemoteStreamOptions(data.Data); PowerShell powershell = RemotingDecoder.GetPowerShell(data.Data); @@ -822,9 +774,7 @@ private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs< data.PowerShellId, data.RunspacePoolId, this, -#if !CORECLR // No ApartmentState In CoreCLR apartmentState, -#endif hostInfo, streamOptions, addToHistory, @@ -881,9 +831,7 @@ private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs< data.PowerShellId, data.RunspacePoolId, this, -#if !CORECLR // No ApartmentState In CoreCLR apartmentState, -#endif hostInfo, streamOptions, addToHistory, @@ -902,9 +850,7 @@ private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs< data.PowerShellId, data.RunspacePoolId, this, -#if !CORECLR // No ApartmentState In CoreCLR apartmentState, -#endif _remoteHost, hostInfo, streamOptions, @@ -935,9 +881,7 @@ private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs< data.PowerShellId, data.RunspacePoolId, this, -#if !CORECLR // No ApartmentState In CoreCLR apartmentState, -#endif hostInfo, streamOptions, addToHistory, @@ -969,9 +913,7 @@ private void HandleCreateAndInvokePowerShell(object sender, RemoteDataEventArgs< data.PowerShellId, data.RunspacePoolId, this, -#if !CORECLR // No ApartmentState In CoreCLR apartmentState, -#endif hostInfo, streamOptions, addToHistory, @@ -1081,9 +1023,7 @@ private void HandleGetCommandMetadata(object sender, RemoteDataEventArgs - /// Default constructor for creating ServerSteppablePipelineDriver...Used by server to concurrently - /// run 2 pipelines. - /// - /// decoded powershell object - /// whether there is input for this powershell - /// the client powershell id - /// the client runspacepool id - /// runspace pool driver - /// which is creating this powershell driver - /// host info using which the host for - /// this powershell will be constructed - /// serialization options for the streams in this powershell - /// - /// true if the command is to be added to history list of the runspace. false, otherwise. - /// - /// - /// If not null, this Runspace will be used to invoke Powershell. - /// If null, the RunspacePool pointed by will be used. - /// - /// - /// Steppable pipeline event subscriber - /// - /// input collection of the PowerShell pipeline - internal ServerSteppablePipelineDriver(PowerShell powershell, bool noInput, Guid clientPowerShellId, - Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, - HostInfo hostInfo, RemoteStreamOptions streamOptions, - bool addToHistory, Runspace rsToUse, ServerSteppablePipelineSubscriber eventSubscriber, PSDataCollection powershellInput) -#else /// /// Default constructor for creating ServerSteppablePipelineDriver...Used by server to concurrently /// run 2 pipelines. @@ -145,15 +113,12 @@ internal ServerSteppablePipelineDriver(PowerShell powershell, bool noInput, Guid Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, ApartmentState apartmentState, HostInfo hostInfo, RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, ServerSteppablePipelineSubscriber eventSubscriber, PSDataCollection powershellInput) -#endif { LocalPowerShell = powershell; InstanceId = clientPowerShellId; RunspacePoolId = clientRunspacePoolId; RemoteStreamOptions = streamOptions; -#if !CORECLR // No ApartmentState In CoreCLR this.apartmentState = apartmentState; -#endif NoInput = noInput; _addToHistory = addToHistory; _eventSubscriber = eventSubscriber; diff --git a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs index d342f4c1155..bc0301b91f4 100644 --- a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs +++ b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs @@ -856,9 +856,7 @@ private void HandleCreateRunspacePool(object sender, RemoteDataEventArgs createR int minRunspaces = RemotingDecoder.GetMinRunspaces(rcvdData.Data); int maxRunspaces = RemotingDecoder.GetMaxRunspaces(rcvdData.Data); PSThreadOptions threadOptions = RemotingDecoder.GetThreadOptions(rcvdData.Data); -#if !CORECLR // No ApartmentState In CoreCLR ApartmentState apartmentState = RemotingDecoder.GetApartmentState(rcvdData.Data); -#endif HostInfo hostInfo = RemotingDecoder.GetHostInfo(rcvdData.Data); if (_runspacePoolDriver != null) @@ -878,9 +876,7 @@ private void HandleCreateRunspacePool(object sender, RemoteDataEventArgs createR minRunspaces, maxRunspaces, threadOptions, -#if !CORECLR // No ApartmentState In CoreCLR apartmentState, -#endif hostInfo, rsSessionStateToUse, applicationPrivateData, diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 16c8032381c..95d8b2231fd 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -509,6 +509,18 @@ foo } } } + + Context "Set ApartmentState" { + It "powershell starts with " -TestCases @( + @{ApartmentState = "STA"}, + @{ApartmentState = "MTA"} + ) { + param($ApartmentState) + + $cmdline = "powershell -noprofile -nologo -$ApartmentState -command [System.Threading.Thread]::CurrentThread.ApartmentState" + Invoke-Expression $cmdline | Should BeExactly $ApartmentState + } + } } Describe "WindowStyle argument" -Tag Feature { From 5887a5033e35f99d0e37461c4add34451fdfa8dc Mon Sep 17 00:00:00 2001 From: "Steve Lee [MSFT]" Date: Tue, 15 Aug 2017 14:39:09 -0700 Subject: [PATCH 2/4] removed difference between coreclr and fullclr code --- .../ConfigProvider.cs | 29 ------------------- .../Microsoft.WSMan.Management.csproj | 1 + 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index 4561a3b6d68..e51541f5f4e 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -16,9 +16,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Security; -#if !CORECLR using System.ServiceProcess; -#endif namespace Microsoft.WSMan.Management { @@ -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); @@ -4463,10 +4458,6 @@ private void AssertError(string ErrorMessage, bool IsWSManError) /// private bool IsWSManServiceRunning() { -#if CORECLR - // TODO once s78 comes in undo this - return true; -#else ServiceController svc = new ServiceController("WinRM"); if (svc != null) { @@ -4476,7 +4467,6 @@ private bool IsWSManServiceRunning() } } return false; -#endif } /// @@ -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) { @@ -4559,7 +4547,6 @@ private bool IsPathLocalMachine(string host) } } } -#endif return hostfound; } @@ -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 "'", then manually convert "'" to "'" since we are encode xml not html; - Value = System.Net.WebUtility.HtmlEncode(ValueAsXML); - Value = Value.Replace("'", "'"); -#else Value = SecurityElement.Escape(ValueAsXML); -#endif } } objInitParam.Properties.Add(new PSNoteProperty(Name, Value)); @@ -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; diff --git a/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj b/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj index 6403c25a5e5..40092384e4f 100644 --- a/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj +++ b/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj @@ -10,6 +10,7 @@ + From 9a7782de7593088681b16bfb291dee18010b0b1c Mon Sep 17 00:00:00 2001 From: "Steve Lee [MSFT]" Date: Thu, 17 Aug 2017 04:59:21 -0700 Subject: [PATCH 3/4] [feature] fix WSMan provider --- src/Microsoft.WSMan.Management/CredSSP.cs | 39 +-------- src/Microsoft.WSMan.Management/Interop.cs | 85 +------------------ src/Microsoft.WSMan.Management/WsManHelper.cs | 14 +-- .../engine/hostifaces/LocalPipeline.cs | 41 +-------- 4 files changed, 8 insertions(+), 171 deletions(-) diff --git a/src/Microsoft.WSMan.Management/CredSSP.cs b/src/Microsoft.WSMan.Management/CredSSP.cs index 29b71c14f3c..8ec66f3755d 100644 --- a/src/Microsoft.WSMan.Management/CredSSP.cs +++ b/src/Microsoft.WSMan.Management/CredSSP.cs @@ -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; @@ -335,15 +333,6 @@ private void DeleteDelegateSettings(string applicationname, RegistryKey rootKey, /// 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(); @@ -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)) @@ -725,11 +706,7 @@ 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 -#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); @@ -737,11 +714,7 @@ private void UpdateGPORegistrySettings(string applicationname, string[] delegate // 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 -#endif - ); + Allow_Fresh_Credential_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials); if (Allow_Fresh_Credential_Key != null) { @@ -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"); - throw new InvalidOperationException(message); - } -#endif IWSManSession m_SessionObj = null; try diff --git a/src/Microsoft.WSMan.Management/Interop.cs b/src/Microsoft.WSMan.Management/Interop.cs index 7a15b30cc96..e12fac39e88 100644 --- a/src/Microsoft.WSMan.Management/Interop.cs +++ b/src/Microsoft.WSMan.Management/Interop.cs @@ -181,15 +181,10 @@ public enum AuthenticationMechanism [Guid("190D8637-5CD3-496D-AD24-69636BB5A3B5")] [ComImport] [TypeLibType((short)4304)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif public interface IWSMan { -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object GetTypeInfoCount(); @@ -201,30 +196,20 @@ public interface IWSMan [return: MarshalAs(UnmanagedType.IUnknown)] object Invoke(); -#endif /// CreateSession method of IWSMan interface. /// An original IDL definition of CreateSession method was the following: HRESULT CreateSession ([optional, defaultvalue("")] BSTR connection, [optional, defaultvalue(0)] long flags, [optional] IDispatch* connectionOptions, [out, retval] IDispatch** ReturnValue); // IDL: HRESULT CreateSession ([optional, defaultvalue("")] BSTR connection, [optional, defaultvalue(0)] long flags, [optional] IDispatch* connectionOptions, [out, retval] IDispatch** ReturnValue); [DispId(1)] -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object CreateSession([MarshalAs(UnmanagedType.BStr)] string connection, int flags, [MarshalAs(UnmanagedType.IUnknown)] object connectionOptions); -#else - [return: MarshalAs(UnmanagedType.IDispatch)] - object CreateSession([MarshalAs(UnmanagedType.BStr)] string connection, int flags, [MarshalAs(UnmanagedType.IDispatch)] object connectionOptions); -#endif /// CreateConnectionOptions method of IWSMan interface. /// An original IDL definition of CreateConnectionOptions method was the following: HRESULT CreateConnectionOptions ([out, retval] IDispatch** ReturnValue); // IDL: HRESULT CreateConnectionOptions ([out, retval] IDispatch** ReturnValue); // [DispId(2)] -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] -#else - [return: MarshalAs(UnmanagedType.IDispatch)] -#endif object CreateConnectionOptions(); /// CommandLine property of IWSMan interface. @@ -263,15 +248,10 @@ string Error [Guid("F704E861-9E52-464F-B786-DA5EB2320FDD")] [ComImport] [TypeLibType((short)4288)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif [SuppressMessage("Microsoft.Design", "CA1044:PropertiesShouldNotBeWriteOnly")] public interface IWSManConnectionOptions { -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object GetTypeInfoCount(); @@ -283,7 +263,6 @@ public interface IWSManConnectionOptions [return: MarshalAs(UnmanagedType.IUnknown)] object Invoke(); -#endif /// UserName property of IWSManConnectionOptions interface. /// An original IDL definition of UserName property was the following: BSTR UserName; // IDL: BSTR UserName; @@ -320,11 +299,7 @@ string Password [Guid("EF43EDF7-2A48-4d93-9526-8BD6AB6D4A6B")] [ComImport] [TypeLibType((short)4288)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] public interface IWSManConnectionOptionsEx : IWSManConnectionOptions { @@ -345,11 +320,7 @@ string CertificateThumbprint [Guid("F500C9EC-24EE-48ab-B38D-FC9A164C658E")] [ComImport] [TypeLibType((short)4288)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif public interface IWSManConnectionOptionsEx2 : IWSManConnectionOptionsEx { /// SetProxy method of IWSManConnectionOptionsEx2 interface. @@ -396,15 +367,10 @@ void SetProxy(int accessType, [Guid("F3457CA9-ABB9-4FA5-B850-90E8CA300E7F")] [ComImport] [TypeLibType((short)4288)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif public interface IWSManEnumerator { -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object GetTypeInfoCount(); @@ -416,7 +382,6 @@ public interface IWSManEnumerator [return: MarshalAs(UnmanagedType.IUnknown)] object Invoke(); -#endif /// ReadItem method of IWSManEnumerator interface. /// An original IDL definition of ReadItem method was the following: HRESULT ReadItem ([out, retval] BSTR* ReturnValue); @@ -460,18 +425,13 @@ string Error [ComImport] [TypeLibType((short)4304)] [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "str")] [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cred")] [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Username")] [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Error")] public interface IWSManEx { -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object GetTypeInfoCount(); @@ -483,32 +443,21 @@ public interface IWSManEx [return: MarshalAs(UnmanagedType.IUnknown)] object Invoke(); -#endif /// CreateSession method of IWSManEx interface. /// An original IDL definition of CreateSession method was the following: HRESULT CreateSession ([optional, defaultvalue("")] BSTR connection, [optional, defaultvalue(0)] long flags, [optional] IDispatch* connectionOptions, [out, retval] IDispatch** ReturnValue); // IDL: HRESULT CreateSession ([optional, defaultvalue("")] BSTR connection, [optional, defaultvalue(0)] long flags, [optional] IDispatch* connectionOptions, [out, retval] IDispatch** ReturnValue); [DispId(1)] -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object CreateSession([MarshalAs(UnmanagedType.BStr)] string connection, int flags, [MarshalAs(UnmanagedType.IUnknown)] object connectionOptions); -#else - [return: MarshalAs(UnmanagedType.IDispatch)] - object CreateSession([MarshalAs(UnmanagedType.BStr)] string connection, int flags, [MarshalAs(UnmanagedType.IDispatch)] object connectionOptions); -#endif - /// CreateConnectionOptions method of IWSManEx interface. /// An original IDL definition of CreateConnectionOptions method was the following: HRESULT CreateConnectionOptions ([out, retval] IDispatch** ReturnValue); // IDL: HRESULT CreateConnectionOptions ([out, retval] IDispatch** ReturnValue); [DispId(2)] -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] -#else - [return: MarshalAs(UnmanagedType.IDispatch)] -#endif object CreateConnectionOptions(); @@ -548,11 +497,7 @@ string Error [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "str")] [DispId(5)] -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] -#else - [return: MarshalAs(UnmanagedType.IDispatch)] -#endif object CreateResourceLocator([MarshalAs(UnmanagedType.BStr)] string strResourceLocator); /// SessionFlagUTF8 method of IWSManEx interface. @@ -723,16 +668,9 @@ string Error [Guid("A7A1BA28-DE41-466A-AD0A-C4059EAD7428")] [ComImport] [TypeLibType((short)4288)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif - - public interface IWSManResourceLocator { -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object GetTypeInfoCount(); @@ -744,7 +682,7 @@ public interface IWSManResourceLocator [return: MarshalAs(UnmanagedType.IUnknown)] object Invoke(); -#endif + /// resourceUri property of IWSManResourceLocator interface. Set the resource URI. Must contain path only -- query string is not allowed here. /// An original IDL definition of resourceUri property was the following: BSTR resourceUri; // Set the resource URI. Must contain path only -- query string is not allowed here. @@ -892,19 +830,13 @@ string Error [Guid("FC84FC58-1286-40C4-9DA0-C8EF6EC241E0")] [ComImport] [TypeLibType((short)4288)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif - [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Error")] [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#")] [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "URI")] public interface IWSManSession { -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object GetTypeInfoCount(); @@ -916,7 +848,6 @@ public interface IWSManSession [return: MarshalAs(UnmanagedType.IUnknown)] object Invoke(); -#endif /// Get method of IWSManSession interface. /// An original IDL definition of Get method was the following: HRESULT Get (VARIANT resourceUri, [optional, defaultvalue(0)] long flags, [out, retval] BSTR* ReturnValue); @@ -971,11 +902,7 @@ public interface IWSManSession // IDL: HRESULT Enumerate (VARIANT resourceUri, [optional, defaultvalue("")] BSTR filter, [optional, defaultvalue("")] BSTR dialect, [optional, defaultvalue(0)] long flags, [out, retval] IDispatch** ReturnValue); [DispId(6)] -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] -#else - [return: MarshalAs(UnmanagedType.IDispatch)] -#endif object Enumerate(object resourceUri, [MarshalAs(UnmanagedType.BStr)] string filter, [MarshalAs(UnmanagedType.BStr)] string dialect, int flags); /// Identify method of IWSManSession interface. @@ -1043,15 +970,10 @@ int Timeout [Guid("EFFAEAD7-7EC8-4716-B9BE-F2E7E9FB4ADB")] [ComImport] [TypeLibType((short)400)] -#if CORECLR [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] -#else - [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] -#endif [SuppressMessage("Microsoft.Design", "CA1040:AvoidEmptyInterfaces")] public interface IWSManResourceLocatorInternal { -#if CORECLR [return: MarshalAs(UnmanagedType.IUnknown)] object GetTypeInfoCount(); @@ -1063,7 +985,6 @@ public interface IWSManResourceLocatorInternal [return: MarshalAs(UnmanagedType.IUnknown)] object Invoke(); -#endif } #endregion IWSManResourceLocatorInternal @@ -1072,11 +993,7 @@ public interface IWSManResourceLocatorInternal /// WSMan interface. [Guid("BCED617B-EC03-420b-8508-977DC7A686BD")] [ComImport] -#if CORECLR [ClassInterface(ClassInterfaceType.None)] -#else - [ClassInterface(ClassInterfaceType.AutoDual)] -#endif public class WSManClass { } diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index d33423ddf00..e805b12d947 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -17,9 +17,7 @@ using System.Management.Automation; using System.Management.Automation.Provider; using System.Threading; -#if CORECLR using System.Xml.XPath; -#endif namespace Microsoft.WSMan.Management { @@ -1009,17 +1007,11 @@ internal bool ValidateCredSSPRegistry(bool AllowFreshCredentialsValueShouldBePre { RegistryKey rGPOLocalMachineKey = Registry.LocalMachine.OpenSubKey( Registry_Path_Credentials_Delegation + @"\CredentialsDelegation", -#if !CORECLR - RegistryKeyPermissionCheck.ReadWriteSubTree, -#endif - System.Security.AccessControl.RegistryRights.FullControl); + System.Security.AccessControl.RegistryRights.FullControl); if (rGPOLocalMachineKey != null) { rGPOLocalMachineKey = rGPOLocalMachineKey.OpenSubKey(Key_Allow_Fresh_Credentials, -#if !CORECLR - RegistryKeyPermissionCheck.ReadWriteSubTree, -#endif System.Security.AccessControl.RegistryRights.FullControl); if (rGPOLocalMachineKey == null) { @@ -1078,11 +1070,7 @@ internal static void LoadResourceData() try { string filepath = System.Environment.ExpandEnvironmentVariables("%Windir%") + "\\System32\\Winrm\\" + -#if CORECLR "0409" /* TODO: don't assume it is always English on CSS? */ -#else - String.Concat("0", String.Format(CultureInfo.CurrentCulture, "{0:x2}", checked((uint)CultureInfo.CurrentUICulture.LCID))) -#endif + "\\" + "winrm.ini"; if (File.Exists(filepath)) { diff --git a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs index 59ccaa3b2d4..eb3e9bad4d6 100644 --- a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs +++ b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs @@ -156,6 +156,7 @@ protected override void StartPipelineExecution() Thread invokeThread = new Thread(new ThreadStart(this.InvokeThreadProc), MaxStack); SetupInvokeThread(invokeThread, true); +#if !UNIX ApartmentState apartmentState; if (InvocationSettings != null && InvocationSettings.ApartmentState != ApartmentState.Unknown) @@ -171,6 +172,7 @@ protected override void StartPipelineExecution() { invokeThread.SetApartmentState(apartmentState); } +#endif invokeThread.Start(); break; @@ -247,44 +249,9 @@ internal static int MaxStack { get { - int i = ReadRegistryInt("PipelineMaxStackSizeMB", 10); // TODO: move to startupconfig - if (i < 10) - i = 10; // minimum 10MB - else if (i > 100) - i = 100; // maximum 100MB - return i * 1000000; - } - } - - internal static int ReadRegistryInt(string policyValueName, int defaultValue) - { - RegistryKey key; - try - { - key = Registry.LocalMachine.OpenSubKey(Utils.GetRegistryConfigurationPrefix()); - } - catch (System.Security.SecurityException) - { - return defaultValue; - } - if (null == key) - return defaultValue; - - object temp; - try - { - temp = key.GetValue(policyValueName); - } - catch (System.Security.SecurityException) - { - return defaultValue; - } - if (!(temp is int)) - { - return defaultValue; + // TODO: move this to startupconfig is needed. This number is in bytes. + return 10000000; } - int i = (int)temp; - return i; } /// From 080f45080ba29fd5b6a5f81b212b4515e5e5b1e7 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 8 Sep 2017 09:18:16 -0700 Subject: [PATCH 4/4] improved comment about deprecated TimeZone property --- .../engine/remoting/common/WireDataFormat/EncodeAndDecode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs index c365a03bd26..d9499bcd969 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs @@ -2387,7 +2387,7 @@ internal static RemoteSessionCapability GetSessionCapability(object data) // // So just return the CurrentTimeZone. -#if !CORECLR // TimeZone deprecated, need to change to TimeZoneInfo +#if !CORECLR // TODO: TimeZone deprecated, need to change to TimeZoneInfo. Affects serialization, remoting, and backwards compatibility. result.TimeZone = TimeZone.CurrentTimeZone; #endif }