Avoid calling static members from 'Microsoft.Win32.Registry' on UNIX, especially the code that would run in TypeInitializer.
This is because with the latest .NET Core packages (1.1.0 preview), calling static members from 'Microsoft.Win32.Registry' will raise 'PlatformNotSupportedException'.
This commit is contained in:
parent
a1aac43f1b
commit
d0c60e049d
|
@ -200,8 +200,12 @@ namespace System.Management.Automation
|
||||||
return ecFromTLS.TypeTable;
|
return ecFromTLS.TypeTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !UNIX
|
||||||
private static string s_pshome = null;
|
private static string s_pshome = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the application base path of the shell from registry
|
||||||
|
/// </summary>
|
||||||
internal static string GetApplicationBaseFromRegistry(string shellId)
|
internal static string GetApplicationBaseFromRegistry(string shellId)
|
||||||
{
|
{
|
||||||
bool wantPsHome = (object)shellId == (object)DefaultPowerShellShellID;
|
bool wantPsHome = (object)shellId == (object)DefaultPowerShellShellID;
|
||||||
|
@ -226,6 +230,7 @@ namespace System.Management.Automation
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the application base for current monad version
|
/// Gets the application base for current monad version
|
||||||
|
@ -616,13 +621,18 @@ namespace System.Management.Automation
|
||||||
return GetRegistryConfigurationPrefix() + "\\" + shellID;
|
return GetRegistryConfigurationPrefix() + "\\" + shellID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves group policy settings based on the preference order provided:
|
// Calling static members of 'Registry' on UNIX will raise 'PlatformNotSupportedException'
|
||||||
// Dictionary<string, object> settings = GetGroupPolicySetting("Transcription", Registry.LocalMachine, Registry.CurrentUser);
|
#if UNIX
|
||||||
|
internal static RegistryKey[] RegLocalMachine = null;
|
||||||
|
internal static RegistryKey[] RegCurrentUser = null;
|
||||||
|
internal static RegistryKey[] RegLocalMachineThenCurrentUser = null;
|
||||||
|
internal static RegistryKey[] RegCurrentUserThenLocalMachine = null;
|
||||||
|
#else
|
||||||
internal static RegistryKey[] RegLocalMachine = new[] { Registry.LocalMachine };
|
internal static RegistryKey[] RegLocalMachine = new[] { Registry.LocalMachine };
|
||||||
internal static RegistryKey[] RegCurrentUser = new[] { Registry.CurrentUser };
|
internal static RegistryKey[] RegCurrentUser = new[] { Registry.CurrentUser };
|
||||||
internal static RegistryKey[] RegLocalMachineThenCurrentUser = new[] { Registry.LocalMachine, Registry.CurrentUser };
|
internal static RegistryKey[] RegLocalMachineThenCurrentUser = new[] { Registry.LocalMachine, Registry.CurrentUser };
|
||||||
internal static RegistryKey[] RegCurrentUserThenLocalMachine = new[] { Registry.CurrentUser, Registry.LocalMachine };
|
internal static RegistryKey[] RegCurrentUserThenLocalMachine = new[] { Registry.CurrentUser, Registry.LocalMachine };
|
||||||
|
#endif
|
||||||
|
|
||||||
internal static Dictionary<string, object> GetGroupPolicySetting(string settingName, RegistryKey[] preferenceOrder)
|
internal static Dictionary<string, object> GetGroupPolicySetting(string settingName, RegistryKey[] preferenceOrder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -247,6 +247,7 @@ namespace System.Management.Automation.Runspaces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !CORECLR
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stack Reserve setting for pipeline threads
|
/// Stack Reserve setting for pipeline threads
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -263,6 +264,38 @@ namespace System.Management.Automation.Runspaces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
int i = (int)temp;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
/// Helper method for asynchronous invoke
|
/// Helper method for asynchronous invoke
|
||||||
///<returns>Unhandled FlowControl exception if InvocationSettings.ExposeFlowControlExceptions is true.</returns>
|
///<returns>Unhandled FlowControl exception if InvocationSettings.ExposeFlowControlExceptions is true.</returns>
|
||||||
|
@ -531,40 +564,6 @@ namespace System.Management.Automation.Runspaces
|
||||||
return flowControlException;
|
return flowControlException;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NTRAID#Windows Out Of Band Releases-915506-2005/09/09
|
|
||||||
// Removed HandleUnexpectedExceptions infrastructure
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
int i = (int)temp;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NTRAID#Windows Out Of Band Releases-915506-2005/09/09
|
// NTRAID#Windows Out Of Band Releases-915506-2005/09/09
|
||||||
// Removed HandleUnexpectedExceptions infrastructure
|
// Removed HandleUnexpectedExceptions infrastructure
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue