Address PR feedback
authorStephen Toub <stoub@microsoft.com>
Thu, 23 Jun 2016 17:58:03 +0000 (13:58 -0400)
committerStephen Toub <stoub@microsoft.com>
Thu, 23 Jun 2016 17:58:39 +0000 (13:58 -0400)
And additional minor cleanup.

Commit migrated from https://github.com/dotnet/corefx/commit/3ba84a89277b525b069961701f75a58eb5334df1

src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/Registry.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.FileSystem.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.Windows.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/ThrowHelper.cs
src/libraries/Microsoft.Win32.Registry/src/project.json

index b656c66..1dee7e9 100644 (file)
@@ -4,7 +4,6 @@
 
 using System;
 using System.Diagnostics;
-using System.Security;
 
 namespace Microsoft.Win32
 {
@@ -29,7 +28,6 @@ namespace Microsoft.Win32
         /// <summary>Current Config Root Key. This is where current configuration information is stored.</summary>
         public static readonly RegistryKey CurrentConfig = RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Default);
 
-        [SecuritySafeCritical]
         public static object GetValue(string keyName, string valueName, object defaultValue)
         {
             string subKeyName;
@@ -37,9 +35,7 @@ namespace Microsoft.Win32
 
             using (RegistryKey key = basekey.OpenSubKey(subKeyName))
             {
-                return key != null ?
-                    key.GetValue(valueName, defaultValue) :
-                    null;
+                return key?.GetValue(valueName, defaultValue);
             }
         }
 
@@ -48,7 +44,6 @@ namespace Microsoft.Win32
             SetValue(keyName, valueName, value, RegistryValueKind.Unknown);
         }
 
-        [SecuritySafeCritical]
         public static void SetValue(string keyName, string valueName, object value, RegistryValueKind valueKind)
         {
             string subKeyName;
@@ -67,7 +62,6 @@ namespace Microsoft.Win32
         /// If the keyName is not valid, we will throw ArgumentException.
         /// The return value shouldn't be null. 
         /// </summary>
-        [System.Security.SecurityCritical]
         private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName)
         {
             if (keyName == null)
index db88827..0c6fa13 100644 (file)
@@ -4,49 +4,42 @@
 
 using Microsoft.Win32.SafeHandles;
 using System;
-using System.Security;
 using System.Security.AccessControl;
 
 namespace Microsoft.Win32
 {
     public sealed partial class RegistryKey : IDisposable
     {
-        [SecuritySafeCritical]
         private void ClosePerfDataKey()
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private void FlushCore()
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private RegistryKey CreateSubKeyInternalCore(string subkey, bool writable, RegistryOptions registryOptions)
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private void DeleteSubKeyCore(string subkey, bool throwOnMissingSubKey)
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private void DeleteSubKeyTreeCore(string subkey)
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private void DeleteValueCore(string name, bool throwOnMissingValue)
         {
             // TODO: Implement this
@@ -59,13 +52,11 @@ namespace Microsoft.Win32
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private static RegistryKey OpenRemoteBaseKeyCore(RegistryHive hKey, string machineName, RegistryView view)
         {
             throw new PlatformNotSupportedException(SR.Security_RegistryPermission); // remote stores not supported on Unix
         }
 
-        [SecurityCritical]
         private RegistryKey InternalOpenSubKeyCore(string name, RegistryRights rights, bool throwOnPermissionFailure)
         {
             // TODO: Implement this
@@ -74,7 +65,6 @@ namespace Microsoft.Win32
 
         private SafeRegistryHandle SystemKeyHandle
         {
-            [SecurityCritical]
             get
             {
                 // TODO: Implement this
@@ -82,60 +72,46 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecurityCritical]
         private int InternalSubKeyCountCore()
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecurityCritical]
         private string[] InternalGetSubKeyNamesCore(int subkeys)
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecurityCritical]
         private int InternalValueCountCore()
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private string[] GetValueNamesCore(int values)
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecurityCritical]
         private Object InternalGetValueCore(string name, Object defaultValue, bool doNotExpand)
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private RegistryValueKind GetValueKindCore(string name)
         {
             // TODO: Implement this
             throw new PlatformNotSupportedException();
         }
 
-        [SecuritySafeCritical]
         private void SetValueCore(string name, Object value, RegistryValueKind valueKind)
         {
-            try
-            { 
-                // TODO: Implement this
-                throw new PlatformNotSupportedException();
-            }
-            catch (Exception exc) when (exc is OverflowException || exc is InvalidOperationException || exc is FormatException || exc is InvalidCastException)
-            {
-                ThrowHelper.ThrowArgumentException(SR.Arg_RegSetMismatchedKind);
-            }
+            // TODO: Implement this
+            throw new PlatformNotSupportedException();
         }
     }
 }
index 1de5045..b4864a6 100644 (file)
@@ -7,7 +7,6 @@ using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
-using System.Security;
 using System.Security.AccessControl;
 
 /*
@@ -58,7 +57,6 @@ namespace Microsoft.Win32
 {
     public sealed partial class RegistryKey : IDisposable
     {
-        [SecuritySafeCritical]
         private void ClosePerfDataKey()
         {
             // System keys should never be closed.  However, we want to call RegCloseKey
@@ -75,7 +73,6 @@ namespace Microsoft.Win32
             Interop.mincore.RegCloseKey(HKEY_PERFORMANCE_DATA);
         }
 
-        [SecuritySafeCritical]
         private void FlushCore()
         {
             if (_hkey != null && IsDirty())
@@ -84,7 +81,6 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecuritySafeCritical]
         private unsafe RegistryKey CreateSubKeyInternalCore(string subkey, bool writable, RegistryOptions registryOptions)
         {
             Interop.mincore.SECURITY_ATTRIBUTES secAttrs = default(Interop.mincore.SECURITY_ATTRIBUTES);
@@ -124,7 +120,6 @@ namespace Microsoft.Win32
             return null;
         }
 
-        [SecuritySafeCritical]
         private void DeleteSubKeyCore(string subkey, bool throwOnMissingSubKey)
         {
             int ret = Interop.mincore.RegDeleteKeyEx(_hkey, subkey, (int)_regView, 0);
@@ -145,7 +140,6 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecuritySafeCritical]
         private void DeleteSubKeyTreeCore(string subkey)
         {
             int ret = Interop.mincore.RegDeleteKeyEx(_hkey, subkey, (int)_regView, 0);
@@ -155,7 +149,6 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecuritySafeCritical]
         private void DeleteValueCore(string name, bool throwOnMissingValue)
         {
             int errorCode = Interop.mincore.RegDeleteValue(_hkey, name);
@@ -195,7 +188,6 @@ namespace Microsoft.Win32
         /// </summary>
         /// <param name="hKeyHive">HKEY_* to open.</param>
         /// <returns>The RegistryKey requested.</returns>
-        [SecuritySafeCritical]
         private static RegistryKey OpenBaseKeyCore(RegistryHive hKeyHive, RegistryView view)
         {
             IntPtr hKey = (IntPtr)((int)hKeyHive);
@@ -214,7 +206,6 @@ namespace Microsoft.Win32
             return key;
         }
 
-        [SecuritySafeCritical]
         private static RegistryKey OpenRemoteBaseKeyCore(RegistryHive hKey, string machineName, RegistryView view)
         {
             int index = (int)hKey & 0x0FFFFFFF;
@@ -249,7 +240,6 @@ namespace Microsoft.Win32
             return key;
         }
 
-        [SecurityCritical]
         private RegistryKey InternalOpenSubKeyCore(string name, RegistryRights rights, bool throwOnPermissionFailure)
         {
             SafeRegistryHandle result = null;
@@ -277,7 +267,6 @@ namespace Microsoft.Win32
 
         private SafeRegistryHandle SystemKeyHandle
         {
-            [SecurityCritical]
             get
             {
                 Debug.Assert(IsSystemKey());
@@ -329,7 +318,6 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecurityCritical]
         private int InternalSubKeyCountCore()
         {
             int subkeys = 0;
@@ -355,7 +343,6 @@ namespace Microsoft.Win32
             return subkeys;
         }
 
-        [SecurityCritical]
         private unsafe string[] InternalGetSubKeyNamesCore(int subkeys)
         {
             string[] names = new string[subkeys];
@@ -388,7 +375,6 @@ namespace Microsoft.Win32
             return names;
         }
 
-        [SecurityCritical]
         private int InternalValueCountCore()
         {
             int values = 0;
@@ -415,7 +401,6 @@ namespace Microsoft.Win32
 
         /// <summary>Retrieves an array of strings containing all the value names.</summary>
         /// <returns>All value names.</returns>
-        [SecuritySafeCritical]
         private unsafe string[] GetValueNamesCore(int values)
         {
             string[] names = new string[values];
@@ -451,7 +436,6 @@ namespace Microsoft.Win32
             return names;
         }
 
-        [SecurityCritical]
         private object InternalGetValueCore(string name, object defaultValue, bool doNotExpand)
         {
             object data = defaultValue;
@@ -689,7 +673,6 @@ namespace Microsoft.Win32
             return data;
         }
 
-        [SecuritySafeCritical]
         private RegistryValueKind GetValueKindCore(string name)
         {
             int type = 0;
@@ -706,7 +689,6 @@ namespace Microsoft.Win32
                 (RegistryValueKind)type;
         }
 
-        [SecuritySafeCritical]
         private unsafe void SetValueCore(string name, object value, RegistryValueKind valueKind)
         {
             int ret = 0;
@@ -832,7 +814,6 @@ namespace Microsoft.Win32
         /// error, and depending on the error, insert a string into the message
         /// gotten from the ResourceManager.
         /// </summary>
-        [SecuritySafeCritical]
         private void Win32Error(int errorCode, string str)
         {
             switch (errorCode)
@@ -868,7 +849,6 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecuritySafeCritical]
         private static void Win32ErrorStatic(int errorCode, string str)
         {
             switch (errorCode)
index ac18416..f754cff 100644 (file)
@@ -6,9 +6,7 @@ using Microsoft.Win32.SafeHandles;
 using System;
 using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
-using System.Diagnostics.Contracts;
 using System.IO;
-using System.Security;
 using System.Security.AccessControl;
 using System.Text;
 
@@ -42,7 +40,6 @@ namespace Microsoft.Win32
         private const int MaxKeyLength = 255;
         private const int MaxValueLength = 16383;
 
-        [SecurityCritical]
         private volatile SafeRegistryHandle _hkey;
         private volatile string _keyName;
         private volatile bool _remoteKey;
@@ -52,7 +49,6 @@ namespace Microsoft.Win32
         /// <summary>
         /// Creates a RegistryKey. This key is bound to hkey, if writable is <b>false</b> then no write operations will be allowed.
         /// </summary>
-        [SecurityCritical]
         private RegistryKey(SafeRegistryHandle hkey, bool writable, RegistryView view) :
             this(hkey, writable, false, false, false, view)
         {
@@ -66,7 +62,6 @@ namespace Microsoft.Win32
         /// The remoteKey flag when set to true indicates that we are dealing with registry entries
         /// on a remote machine and requires the program making these calls to have full trust.
         /// </summary>
-        [SecurityCritical]
         private RegistryKey(SafeRegistryHandle hkey, bool writable, bool systemkey, bool remoteKey, bool isPerfData, RegistryView view)
         {
             ValidateKeyView(view);
@@ -90,13 +85,11 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecuritySafeCritical]
         public void Flush()
         {
             FlushCore();
         }
 
-        [SecuritySafeCritical]
         public void Dispose()
         {
             if (_hkey != null)
@@ -142,7 +135,6 @@ namespace Microsoft.Win32
             return CreateSubKeyInternal(subkey, writable, options);
         }
 
-        [SecuritySafeCritical]  
         private RegistryKey CreateSubKeyInternal(string subkey, bool writable, RegistryOptions registryOptions)
         {
             ValidateKeyOptions(registryOptions);
@@ -175,7 +167,6 @@ namespace Microsoft.Win32
             DeleteSubKey(subkey, true);
         }
 
-        [SecuritySafeCritical]  
         public void DeleteSubKey(string subkey, bool throwOnMissingSubKey)
         {
             ValidateKeyName(subkey);
@@ -214,7 +205,6 @@ namespace Microsoft.Win32
             DeleteSubKeyTree(subkey, throwOnMissingSubKey: true);
         }
 
-        [SecuritySafeCritical]  
         public void DeleteSubKeyTree(string subkey, bool throwOnMissingSubKey)
         {
             ValidateKeyName(subkey);
@@ -258,7 +248,6 @@ namespace Microsoft.Win32
         /// An internal version which does no security checks or argument checking.  Skipping the 
         /// security checks should give us a slight perf gain on large trees. 
         /// </summary>
-        [SecurityCritical]  
         private void DeleteSubKeyTreeInternal(string subkey)
         {
             RegistryKey key = InternalOpenSubKey(subkey, true);
@@ -291,14 +280,12 @@ namespace Microsoft.Win32
             DeleteValue(name, true);
         }
 
-        [SecuritySafeCritical]  
         public void DeleteValue(string name, bool throwOnMissingValue)
         {
             EnsureWriteable();
             DeleteValueCore(name, throwOnMissingValue);
         }
 
-        [SecuritySafeCritical]  
         public static RegistryKey OpenBaseKey(RegistryHive hKey, RegistryView view)
         {
             ValidateKeyView(view);
@@ -314,7 +301,6 @@ namespace Microsoft.Win32
             return OpenRemoteBaseKey(hKey, machineName, RegistryView.Default);
         }
 
-        [SecuritySafeCritical]  
         public static RegistryKey OpenRemoteBaseKey(RegistryHive hKey, string machineName, RegistryView view)
         {
             if (machineName == null)
@@ -331,7 +317,6 @@ namespace Microsoft.Win32
         /// read-only access.
         /// </summary>
         /// <returns>the Subkey requested, or <b>null</b> if the operation failed.</returns>
-        [SecuritySafeCritical]
         public RegistryKey OpenSubKey(string name, bool writable)
         {
             return InternalOpenSubKey(name, writable);
@@ -349,7 +334,6 @@ namespace Microsoft.Win32
         /// This required no security checks. This is to get around the Deleting SubKeys which only require
         /// write permission. They call OpenSubKey which required read. Now instead call this function w/o security checks
         /// </summary>
-        [SecurityCritical]  
         private RegistryKey InternalOpenSubKey(string name, bool writable)
         {
             ValidateKeyName(name);
@@ -360,7 +344,6 @@ namespace Microsoft.Win32
         /// <summary>Returns a subkey with read only permissions.</summary>
         /// <param name="name">Name or path of subkey to open.</param>
         /// <returns>The Subkey requested, or <b>null</b> if the operation failed.</returns>
-        [SecurityCritical]
         public RegistryKey OpenSubKey(string name)
         {
             return OpenSubKey(name, false);
@@ -370,13 +353,11 @@ namespace Microsoft.Win32
         /// <returns>A count of subkeys.</returns>
         public int SubKeyCount
         {
-            [SecuritySafeCritical]  
             get { return InternalSubKeyCount(); }
         }
 
         public RegistryView View
         {
-            [SecuritySafeCritical]
             get
             {
                 EnsureNotDisposed();
@@ -386,7 +367,6 @@ namespace Microsoft.Win32
 
         public SafeRegistryHandle Handle
         {
-            [SecurityCritical]
             get
             {
                 EnsureNotDisposed();
@@ -394,13 +374,11 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecurityCritical]
         public static RegistryKey FromHandle(SafeRegistryHandle handle)
         {
             return FromHandle(handle, RegistryView.Default);
         }
 
-        [SecurityCritical]
         public static RegistryKey FromHandle(SafeRegistryHandle handle, RegistryView view)
         {
             if (handle == null) throw new ArgumentNullException(nameof(handle));
@@ -409,7 +387,6 @@ namespace Microsoft.Win32
             return new RegistryKey(handle, writable: true, view: view);
         }
 
-        [SecurityCritical]  
         private int InternalSubKeyCount()
         {
             EnsureNotDisposed();
@@ -418,16 +395,13 @@ namespace Microsoft.Win32
 
         /// <summary>Retrieves an array of strings containing all the subkey names.</summary>
         /// <returns>All subkey names.</returns>
-        [SecurityCritical] 
         public string[] GetSubKeyNames()
         {
             return InternalGetSubKeyNames();
         }
 
-        [SecurityCritical]  
         private string[] InternalGetSubKeyNames()
         {
-            EnsureNotDisposed();
             int subkeys = InternalSubKeyCount();
             return subkeys > 0 ?
                 InternalGetSubKeyNamesCore(subkeys) :
@@ -438,25 +412,18 @@ namespace Microsoft.Win32
         /// <returns>A count of values.</returns>
         public int ValueCount
         {
-            [SecuritySafeCritical]  
-            get { return InternalValueCount(); }
-        }
-
-        [SecurityCritical]  
-        private int InternalValueCount()
-        {
-            EnsureNotDisposed();
-            return InternalValueCountCore();
+            get
+            {
+                EnsureNotDisposed();
+                return InternalValueCountCore();
+            }
         }
 
         /// <summary>Retrieves an array of strings containing all the value names.</summary>
         /// <returns>All value names.</returns>
-        [SecuritySafeCritical]  
         public string[] GetValueNames()
         {
-            EnsureNotDisposed();
-
-            int values = InternalValueCount();
+            int values = ValueCount;
             return values > 0 ?
                 GetValueNamesCore(values) :
                 Array.Empty<string>();
@@ -469,7 +436,6 @@ namespace Microsoft.Win32
         /// </remarks>
         /// <param name="name">Name of value to retrieve.</param>
         /// <returns>The data associated with the value.</returns>
-        [SecuritySafeCritical]  
         public object GetValue(string name)
         {
             return InternalGetValue(name, null, false, true);
@@ -487,13 +453,11 @@ namespace Microsoft.Win32
         /// <param name="name">Name of value to retrieve.</param>
         /// <param name="defaultValue">Value to return if <i>name</i> doesn't exist.</param>
         /// <returns>The data associated with the value.</returns>
-        [SecuritySafeCritical]
         public object GetValue(string name, object defaultValue)
         {
             return InternalGetValue(name, defaultValue, false, true);
         }
 
-        [SecuritySafeCritical]
         public object GetValue(string name, object defaultValue, RegistryValueOptions options)
         {
             if (options < RegistryValueOptions.None || options > RegistryValueOptions.DoNotExpandEnvironmentNames)
@@ -504,7 +468,6 @@ namespace Microsoft.Win32
             return InternalGetValue(name, defaultValue, doNotExpand, checkSecurity: true);
         }
 
-        [SecurityCritical]  
         private object InternalGetValue(string name, object defaultValue, bool doNotExpand, bool checkSecurity)
         {
             if (checkSecurity)
@@ -516,7 +479,6 @@ namespace Microsoft.Win32
             return InternalGetValueCore(name, defaultValue, doNotExpand);
         }
 
-        [SecuritySafeCritical]  
         public RegistryValueKind GetValueKind(string name)
         {
             EnsureNotDisposed();
@@ -525,7 +487,6 @@ namespace Microsoft.Win32
 
         public string Name
         {
-            [SecuritySafeCritical]  
             get
             {
                 EnsureNotDisposed();
@@ -541,7 +502,6 @@ namespace Microsoft.Win32
             SetValue(name, value, RegistryValueKind.Unknown);
         }
 
-        [SecuritySafeCritical]
         public void SetValue(string name, object value, RegistryValueKind valueKind)
         {
             if (value == null)
@@ -603,7 +563,6 @@ namespace Microsoft.Win32
 
         /// <summary>Retrieves a string representation of this key.</summary>
         /// <returns>A string representing the key.</returns>
-        [SecuritySafeCritical]  
         public override string ToString()
         {
             EnsureNotDisposed();
@@ -631,7 +590,8 @@ namespace Microsoft.Win32
 
         private static void FixupPath(StringBuilder path)
         {
-            Contract.Requires(path != null);
+            Debug.Assert(path != null);
+
             int length = path.Length;
             bool fixup = false;
             char markerChar = (char)0xFFFF;
@@ -671,7 +631,6 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecurityCritical]  
         private void EnsureNotDisposed()
         {
             if (_hkey == null)
@@ -680,7 +639,6 @@ namespace Microsoft.Win32
             }
         }
 
-        [SecurityCritical]  
         private void EnsureWriteable()
         {
             EnsureNotDisposed();
@@ -692,7 +650,6 @@ namespace Microsoft.Win32
 
         private static void ValidateKeyName(string name)
         {
-            Contract.Ensures(name != null);
             if (name == null)
             {
                 ThrowHelper.ThrowArgumentNullException(nameof(name));
index 04001a7..4db6645 100644 (file)
@@ -3,17 +3,12 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Runtime.InteropServices;
-using System.Security;
 
 namespace Microsoft.Win32.SafeHandles
 {
     public sealed partial class SafeRegistryHandle : SafeHandle
     {
-        [SecurityCritical]
-        protected override bool ReleaseHandle()
-        {
-            // TODO: implement this if necessary
-            return true;
-        }
+        // TODO: implement this if necessary
+        protected override bool ReleaseHandle() => true;
     }
 }
index 5ef4e6f..b680479 100644 (file)
@@ -3,16 +3,12 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Runtime.InteropServices;
-using System.Security;
 
 namespace Microsoft.Win32.SafeHandles
 {
     public sealed partial class SafeRegistryHandle : SafeHandle
     {
-        [SecurityCritical]
-        protected override bool ReleaseHandle()
-        {
-            return (Interop.mincore.RegCloseKey(handle) == Interop.mincore.Errors.ERROR_SUCCESS);
-        }
+        protected override bool ReleaseHandle() =>
+            Interop.mincore.RegCloseKey(handle) == Interop.mincore.Errors.ERROR_SUCCESS;
     }
 }
index 7e5479c..f904c0d 100644 (file)
@@ -4,26 +4,18 @@
 
 using System;
 using System.Runtime.InteropServices;
-using System.Security;
 
 namespace Microsoft.Win32.SafeHandles
 {
-    [SecurityCritical]
     public sealed partial class SafeRegistryHandle : SafeHandle
     {
-        [SecurityCritical]
         internal SafeRegistryHandle() : base(IntPtr.Zero, true) { }
 
-        [SecurityCritical]
         public SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
         {
             SetHandle(preexistingHandle);
         }
 
-        public override bool IsInvalid
-        {
-            [SecurityCritical]
-            get { return handle == new IntPtr(0) || handle == new IntPtr(-1); }
-        }
+        public override bool IsInvalid => handle == IntPtr.Zero || handle == new IntPtr(-1);
     }
 }
index b9e63b6..cb7d04a 100644 (file)
@@ -3,11 +3,10 @@
 // See the LICENSE file in the project root for more information.
 
 using System;
-using System.Diagnostics.Contracts;
+using System.Security;
 
 namespace Microsoft.Win32
 {
-    [Pure]
     internal static class ThrowHelper
     {
         internal static void ThrowArgumentException(string msg)
@@ -32,7 +31,7 @@ namespace Microsoft.Win32
 
         internal static void ThrowSecurityException(string msg)
         {
-            throw new System.Security.SecurityException(msg);
+            throw new SecurityException(msg);
         }
 
         internal static void ThrowUnauthorizedAccessException(string msg)
index b897a00..4b4aea7 100644 (file)
@@ -9,7 +9,6 @@
       "dependencies": {
         "Microsoft.NETCore.Platforms": "1.0.1",
         "System.Collections": "4.0.10",
-        "System.Diagnostics.Contracts": "4.0.0",
         "System.Diagnostics.Debug": "4.0.10",
         "System.Diagnostics.Tools": "4.0.0",
         "System.Globalization": "4.0.10",