diff options
Diffstat (limited to 'src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime')
33 files changed, 125 insertions, 268 deletions
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs index 5574f3c251..e3c6a926d3 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs @@ -9,6 +9,7 @@ using System.Runtime; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -27,12 +28,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private BindableVectorToCollectionAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // int Count { get } [Pure] - [SecurityCritical] internal int Count() { IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); @@ -47,7 +47,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // bool IsSynchronized { get } [Pure] - [SecurityCritical] internal bool IsSynchronized() { return false; @@ -55,7 +54,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // object SyncRoot { get } [Pure] - [SecurityCritical] internal object SyncRoot() { return this; @@ -63,11 +61,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime // void CopyTo(Array array, int index) [Pure] - [SecurityCritical] internal void CopyTo(Array array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); // ICollection expects the destination array to be single-dimensional. if (array.Rank != 1) @@ -79,7 +76,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime int destLen = array.GetLength(0); if (arrayIndex < destLB) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); // Does the dimension in question have sufficient space to copy the expected number of entries? // We perform this check before valid index check to ensure the exception message is in sync with diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs index 73ebf721ee..d6e50f5164 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs @@ -9,6 +9,7 @@ using System.Runtime; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -27,33 +28,30 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private BindableVectorToListAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // object this[int index] { get } - [SecurityCritical] internal object Indexer_Get(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); return GetAt(_this, (uint)index); } // object this[int index] { set } - [SecurityCritical] internal void Indexer_Set(int index, object value) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); SetAt(_this, (uint)index, value); } // int Add(object value) - [SecurityCritical] internal int Add(object value) { IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); @@ -69,7 +67,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Contains(object item) - [SecurityCritical] internal bool Contains(object item) { IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); @@ -79,7 +76,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - [SecurityCritical] internal void Clear() { IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); @@ -88,7 +84,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // bool IsFixedSize { get } [Pure] - [SecurityCritical] internal bool IsFixedSize() { return false; @@ -96,14 +91,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime // bool IsReadOnly { get } [Pure] - [SecurityCritical] internal bool IsReadOnly() { return false; } // int IndexOf(object item) - [SecurityCritical] internal int IndexOf(object item) { IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); @@ -123,18 +116,16 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Insert(int index, object item) - [SecurityCritical] internal void Insert(int index, object item) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); InsertAtHelper(_this, (uint)index, item); } // bool Remove(object item) - [SecurityCritical] internal void Remove(object item) { IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); @@ -154,11 +145,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void RemoveAt(int index) - [SecurityCritical] internal void RemoveAt(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); RemoveAtHelper(_this, (uint)index); @@ -178,7 +168,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -196,7 +186,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -214,7 +204,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -232,7 +222,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs index c88f13dd0b..702e0c9e52 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs @@ -184,7 +184,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } [Pure] - [SecuritySafeCritical] public Point GetPoint() { if (this.Type != PropertyType.Point) @@ -195,7 +194,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } [Pure] - [SecuritySafeCritical] public Size GetSize() { if (this.Type != PropertyType.Size) @@ -206,7 +204,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } [Pure] - [SecuritySafeCritical] public Rect GetRect() { if (this.Type != PropertyType.Rect) @@ -328,7 +325,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } [Pure] - [SecuritySafeCritical] public Point[] GetPointArray() { if (this.Type != PropertyType.PointArray) @@ -339,7 +335,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } [Pure] - [SecuritySafeCritical] public Size[] GetSizeArray() { if (this.Type != PropertyType.SizeArray) @@ -351,7 +346,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } [Pure] - [SecuritySafeCritical] public Rect[] GetRectArray() { if (this.Type != PropertyType.RectArray) @@ -505,7 +499,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Unbox the data stored in the property value to a structurally equivilent type [Pure] - [SecurityCritical] private unsafe T Unbox<T>(Type expectedBoxedType) where T : struct { Contract.Requires(expectedBoxedType != null); Contract.Requires(Marshal.SizeOf(expectedBoxedType) == Marshal.SizeOf(typeof(T))); @@ -526,7 +519,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Convert the array stored in the property value to a structurally equivilent array type [Pure] - [SecurityCritical] private unsafe T[] UnboxArray<T>(Type expectedArrayElementType) where T : struct { Contract.Requires(expectedArrayElementType != null); Contract.Requires(Marshal.SizeOf(expectedArrayElementType) == Marshal.SizeOf(typeof(T))); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs index e379d38cf3..9705b61148 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs @@ -6,6 +6,7 @@ using System; using System.Collections; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Reflection; using System.Security; @@ -55,7 +56,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { Contract.Requires(wrapper != null); IReference<T> reference = (IReference<T>) wrapper; - Contract.Assert(reference != null, "CLRIReferenceImpl::UnboxHelper - QI'ed for IReference<"+typeof(T)+">, but that failed."); + Debug.Assert(reference != null, "CLRIReferenceImpl::UnboxHelper - QI'ed for IReference<"+typeof(T)+">, but that failed."); return reference.Value; } } @@ -216,7 +217,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { Contract.Requires(wrapper != null); IReferenceArray<T> reference = (IReferenceArray<T>)wrapper; - Contract.Assert(reference != null, "CLRIReferenceArrayImpl::UnboxHelper - QI'ed for IReferenceArray<" + typeof(T) + ">, but that failed."); + Debug.Assert(reference != null, "CLRIReferenceArrayImpl::UnboxHelper - QI'ed for IReferenceArray<" + typeof(T) + ">, but that failed."); T[] marshaled = reference.Value; return marshaled; } @@ -229,7 +230,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal static readonly Type s_rectType = Type.GetType("Windows.Foundation.Rect, " + AssemblyRef.SystemRuntimeWindowsRuntime); internal static readonly Type s_sizeType = Type.GetType("Windows.Foundation.Size, " + AssemblyRef.SystemRuntimeWindowsRuntime); - [SecuritySafeCritical] internal static Object CreateIReference(Object obj) { Contract.Requires(obj != null, "Null should not be boxed."); @@ -302,11 +302,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime return Activator.CreateInstance(specificType, new Object[] { propType.Value, obj }); } - Contract.Assert(false, "We should not see non-WinRT type here"); + Debug.Assert(false, "We should not see non-WinRT type here"); return null; } - [SecuritySafeCritical] internal static Object CreateIReferenceArray(Array obj) { Contract.Requires(obj != null); @@ -315,7 +314,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime Type type = obj.GetType().GetElementType(); - Contract.Assert(obj.Rank == 1 && obj.GetLowerBound(0) == 0 && !type.IsArray); + Debug.Assert(obj.Rank == 1 && obj.GetLowerBound(0) == 0 && !type.IsArray); if (type == typeof(int)) return new CLRIReferenceArrayImpl<int>(PropertyType.Int32Array, (int[])obj); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs index af1381c366..a5abb4f23e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs @@ -45,7 +45,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal ConstantSplittableMap(IReadOnlyDictionary<TKey, TValue> data) { if (data == null) - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); Contract.EndContractBlock(); this.firstItemIndex = 0; @@ -56,7 +56,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal ConstantSplittableMap(IMapView<TKey, TValue> data) { if (data == null) - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); if (((UInt32)Int32.MaxValue) < data.Size) { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs index 04fe1bf9b2..d575201bb9 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs @@ -7,6 +7,7 @@ using System; using System.Security; using System.Reflection; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -29,7 +30,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public CustomPropertyImpl(PropertyInfo propertyInfo) { if (propertyInfo == null) - throw new ArgumentNullException("propertyInfo"); + throw new ArgumentNullException(nameof(propertyInfo)); m_property = propertyInfo; } @@ -88,7 +89,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime InvokeInternal(target, new object[] { indexValue, value }, false); } - [SecuritySafeCritical] private object InvokeInternal(object target, object[] args, bool getValue) { // Forward to the right object if we are dealing with a proxy @@ -123,7 +123,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // We can safely skip access check because this is only used in full trust scenarios. // And we have already verified that the property accessor is public. - Contract.Assert(AppDomain.CurrentDomain.PermissionSet.IsUnrestricted()); + Debug.Assert(AppDomain.CurrentDomain.PermissionSet.IsUnrestricted()); return rtMethod.UnsafeInvoke(target, BindingFlags.Default, null, args, null); } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs index c1586ee9ce..c33e002e0e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs @@ -18,7 +18,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public DictionaryKeyCollection(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -26,9 +26,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime public void CopyTo(TKey[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -90,7 +90,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public DictionaryKeyEnumerator(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs index fa021b7f3d..24e5777768 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -28,11 +29,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private DictionaryToMapAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // V Lookup(K key) - [SecurityCritical] internal V Lookup<K, V>(K key) { IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); @@ -50,7 +50,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint Size { get } - [SecurityCritical] internal uint Size<K, V>() { IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); @@ -58,7 +57,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool HasKey(K key) - [SecurityCritical] internal bool HasKey<K, V>(K key) { IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); @@ -66,11 +64,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // IMapView<K, V> GetView() - [SecurityCritical] internal IReadOnlyDictionary<K, V> GetView<K, V>() { IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); - Contract.Assert(_this != null); + Debug.Assert(_this != null); // Note: This dictionary is not really read-only - you could QI for a modifiable // dictionary. We gain some perf by doing this. We believe this is acceptable. @@ -83,7 +80,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Insert(K key, V value) - [SecurityCritical] internal bool Insert<K, V>(K key, V value) { IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); @@ -93,7 +89,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Remove(K key) - [SecurityCritical] internal void Remove<K, V>(K key) { IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); @@ -108,7 +103,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - [SecurityCritical] internal void Clear<K, V>() { IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs index 03e897a917..fcc7755d67 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs @@ -21,7 +21,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { public DictionaryValueCollection(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -29,9 +29,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { public void CopyTo(TValue[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -97,7 +97,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { public DictionaryValueEnumerator(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs index 7329d31ae8..3f9d516162 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs @@ -7,6 +7,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -25,11 +26,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private EnumerableToIterableAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // This method is invoked when First is called on a managed implementation of IIterable<T>. - [System.Security.SecurityCritical] internal IIterator<T> First_Stub<T>() { IEnumerable<T> _this = JitHelpers.UnsafeCast<IEnumerable<T>>(this); @@ -41,7 +41,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private EnumerableToBindableIterableAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } internal sealed class NonGenericToGenericEnumerator : IEnumerator<object> @@ -58,7 +58,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // This method is invoked when First is called on a managed implementation of IBindableIterable. - [System.Security.SecurityCritical] internal IBindableIterator First_Stub() { IEnumerable _this = JitHelpers.UnsafeCast<IEnumerable>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs index 847147ade8..4c6169a4e8 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs @@ -7,6 +7,7 @@ using System; using System.Security; using System.Collections; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; @@ -27,10 +28,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private IDisposableToIClosableAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } - [SecurityCritical] public void Close() { IDisposable _this = JitHelpers.UnsafeCast<IDisposable>(this); @@ -39,15 +39,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // Adapter class which converts IDisposable.Dispose calls into IClosable.Close - [SecurityCritical] internal sealed class IClosableToIDisposableAdapter { private IClosableToIDisposableAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } - [SecurityCritical] private void Dispose() { IClosable _this = JitHelpers.UnsafeCast<IClosable>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs index 143a33e4c7..3bbde35a3c 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs @@ -50,7 +50,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Creates a ICustomProperty implementation for Jupiter // Called from ICustomPropertyProvider_GetIndexedProperty from within runtime // - [System.Security.SecurityCritical] static internal unsafe ICustomProperty CreateIndexedProperty(object target, string propertyName, TypeNameNative *pIndexedParamType) { Contract.Requires(target != null); @@ -87,7 +86,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return new CustomPropertyImpl(propertyInfo); } - [System.Security.SecurityCritical] static internal unsafe void GetType(object target, TypeNameNative *pIndexedParamType) { IGetProxyTarget proxy = target as IGetProxyTarget; @@ -207,7 +205,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // // ICustomQueryInterface methods // - [System.Security.SecurityCritical] public CustomQueryInterfaceResult GetInterface([In]ref Guid iid, out IntPtr ppv) { ppv = IntPtr.Zero; @@ -441,7 +438,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - [SecuritySafeCritical] private IBindableVector GetIBindableVectorNoThrow() { if ((_flags & InterfaceForwardingSupport.IBindableVector) != 0) @@ -450,7 +446,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return null; } - [SecuritySafeCritical] private IVector_Raw<T1> GetVectorOfT() { if ((_flags & InterfaceForwardingSupport.IVector) != 0) @@ -517,7 +512,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime public bool MoveNext() { return _iterator.MoveNext(); } } - [SecuritySafeCritical] private IBindableVectorView GetIBindableVectorViewNoThrow() { if ((_flags & InterfaceForwardingSupport.IBindableVectorView) != 0) @@ -526,7 +520,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return null; } - [SecuritySafeCritical] private IVectorView<T2> GetVectorViewOfT() { if ((_flags & InterfaceForwardingSupport.IVectorView) != 0) diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs index 3600a3ae70..a7424da3fb 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs @@ -28,15 +28,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private IMapViewToIReadOnlyDictionaryAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // V this[K key] { get } - [SecurityCritical] internal V Indexer_Get<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); @@ -44,7 +43,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // IEnumerable<K> Keys { get } - [SecurityCritical] internal IEnumerable<K> Keys<K, V>() { IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); @@ -53,7 +51,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // IEnumerable<V> Values { get } - [SecurityCritical] internal IEnumerable<V> Values<K, V>() { IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); @@ -63,22 +60,20 @@ namespace System.Runtime.InteropServices.WindowsRuntime // bool ContainsKey(K key) [Pure] - [SecurityCritical] internal bool ContainsKey<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); return _this.HasKey(key); } // bool TryGetValue(TKey key, out TValue value) - [SecurityCritical] internal bool TryGetValue<K, V>(K key, out V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); @@ -137,7 +132,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryKeyCollection(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -146,9 +141,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime public void CopyTo(TKey[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -192,7 +187,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryKeyEnumerator(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); @@ -232,7 +227,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryValueCollection(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -241,9 +236,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime public void CopyTo(TValue[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -291,7 +286,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryValueEnumerator(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs index d57f8f1f46..b185b41be0 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs @@ -28,11 +28,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private IReadOnlyDictionaryToIMapViewAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // V Lookup(K key) - [SecurityCritical] internal V Lookup<K, V>(K key) { IReadOnlyDictionary<K, V> _this = JitHelpers.UnsafeCast<IReadOnlyDictionary<K, V>>(this); @@ -50,7 +49,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint Size { get } - [SecurityCritical] internal uint Size<K, V>() { IReadOnlyDictionary<K, V> _this = JitHelpers.UnsafeCast<IReadOnlyDictionary<K, V>>(this); @@ -58,7 +56,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool HasKey(K key) - [SecurityCritical] internal bool HasKey<K, V>(K key) { IReadOnlyDictionary<K, V> _this = JitHelpers.UnsafeCast<IReadOnlyDictionary<K, V>>(this); @@ -66,7 +63,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Split(out IMapView<K, V> first, out IMapView<K, V> second) - [SecurityCritical] internal void Split<K, V>(out IMapView<K, V> first, out IMapView<K, V> second) { IReadOnlyDictionary<K, V> _this = JitHelpers.UnsafeCast<IReadOnlyDictionary<K, V>>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs index 95780bcb13..431d16256e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs @@ -28,11 +28,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private IReadOnlyListToIVectorViewAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // T GetAt(uint index) - [SecurityCritical] internal T GetAt<T>(uint index) { IReadOnlyList<T> _this = JitHelpers.UnsafeCast<IReadOnlyList<T>>(this); @@ -50,7 +49,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint Size { get } - [SecurityCritical] internal uint Size<T>() { IReadOnlyList<T> _this = JitHelpers.UnsafeCast<IReadOnlyList<T>>(this); @@ -58,7 +56,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool IndexOf(T value, out uint index) - [SecurityCritical] internal bool IndexOf<T>(T value, out uint index) { IReadOnlyList<T> _this = JitHelpers.UnsafeCast<IReadOnlyList<T>>(this); @@ -85,7 +82,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint GetMany(uint startIndex, T[] items) - [SecurityCritical] internal uint GetMany<T>(uint startIndex, T[] items) { IReadOnlyList<T> _this = JitHelpers.UnsafeCast<IReadOnlyList<T>>(this); @@ -130,7 +126,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IRestrictedErrorInfo.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IRestrictedErrorInfo.cs index 48bcc4f618..9de5e3f36d 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IRestrictedErrorInfo.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IRestrictedErrorInfo.cs @@ -8,9 +8,7 @@ using System; namespace System.Runtime.InteropServices.WindowsRuntime { -#if FEATURE_CORECLR [System.Runtime.CompilerServices.FriendAccessAllowed] -#endif [ComImport] [Guid("82BA7092-4C88-427D-A7BC-16DD93FEB67E")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs index 72d6fa8cc3..37f21307dc 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs @@ -30,15 +30,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private IVectorViewToIReadOnlyListAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // T this[int index] { get } - [SecurityCritical] internal T Indexer_Get<T>(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVectorView<T> _this = JitHelpers.UnsafeCast<IVectorView<T>>(this); @@ -52,14 +51,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } } // T this[int index] { get } - [SecurityCritical] internal T Indexer_Get_Variance<T>(int index) where T : class { bool fUseString; diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs index f1b799aa84..e219a86769 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs @@ -7,6 +7,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -28,11 +29,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private IterableToEnumerableAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // This method is invoked when GetEnumerator is called on a WinRT-backed implementation of IEnumerable<T>. - [SecurityCritical] internal IEnumerator<T> GetEnumerator_Stub<T>() { IIterable<T> _this = JitHelpers.UnsafeCast<IIterable<T>>(this); @@ -43,7 +43,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // and it is possible that the implementation supports IEnumerable<Type>/IEnumerable<string>/IEnumerable<Exception>/ // IEnumerable<array>/IEnumerable<delegate> rather than IEnumerable<T> because T is assignable from Type/string/ // Exception/array/delegate via co-variance. - [SecurityCritical] internal IEnumerator<T> GetEnumerator_Variance_Stub<T>() where T : class { bool fUseString; @@ -70,7 +69,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private BindableIterableToEnumerableAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } private sealed class NonGenericToGenericIterator : IIterator<object> @@ -87,7 +86,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // This method is invoked when GetEnumerator is called on a WinRT-backed implementation of IEnumerable. - [SecurityCritical] internal IEnumerator GetEnumerator_Stub() { IBindableIterable _this = JitHelpers.UnsafeCast<IBindableIterable>(this); @@ -123,10 +121,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // The enumerator has not been advanced to the first element yet. if (!m_isInitialized) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); // The enumerator has reached the end of the collection if (!m_hadCurrent) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return m_current; } } @@ -137,15 +135,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // The enumerator has not been advanced to the first element yet. if (!m_isInitialized) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted(); // The enumerator has reached the end of the collection if (!m_hadCurrent) - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded(); return m_current; } } - [SecuritySafeCritical] public bool MoveNext() { // If we've passed the end of the iteration, IEnumerable<T> should return false, while @@ -187,7 +184,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Translate E_CHANGED_STATE into an InvalidOperationException for an updated enumeration if (Marshal.GetHRForException(e) == __HResults.E_CHANGED_STATE) { - ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); + ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion(); } else { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs index 35dc495d3f..b9fe11557d 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -28,11 +29,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private ListToBindableVectorAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // object GetAt(uint index) - [SecurityCritical] internal object GetAt(uint index) { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -49,7 +49,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint Size { get } - [SecurityCritical] internal uint Size() { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -57,7 +56,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // IBindableVectorView GetView() - [SecurityCritical] internal IBindableVectorView GetView() { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -65,7 +63,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool IndexOf(object value, out uint index) - [SecurityCritical] internal bool IndexOf(object value, out uint index) { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -82,7 +79,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void SetAt(uint index, object value) - [SecurityCritical] internal void SetAt(uint index, object value) { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -99,7 +95,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void InsertAt(uint index, object value) - [SecurityCritical] internal void InsertAt(uint index, object value) { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -121,7 +116,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void RemoveAt(uint index) - [SecurityCritical] internal void RemoveAt(uint index) { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -140,7 +134,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Append(object value) - [SecurityCritical] internal void Append(object value) { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -148,7 +141,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void RemoveAtEnd() - [SecurityCritical] internal void RemoveAtEnd() { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -164,7 +156,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - [SecurityCritical] internal void Clear() { IList _this = JitHelpers.UnsafeCast<IList>(this); @@ -179,7 +170,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs index f760576aaa..2e2ea9b876 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs @@ -25,7 +25,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal ListToBindableVectorViewAdapter(IList list) { if (list == null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.EndContractBlock(); @@ -38,7 +38,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs index 77f3a9464f..b73f4d7a99 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -28,11 +29,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private ListToVectorAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // T GetAt(uint index) - [SecurityCritical] internal T GetAt<T>(uint index) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -49,7 +49,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint Size { get } - [SecurityCritical] internal uint Size<T>() { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -57,11 +56,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // IVectorView<T> GetView() - [SecurityCritical] internal IReadOnlyList<T> GetView<T>() { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); - Contract.Assert(_this != null); + Debug.Assert(_this != null); // Note: This list is not really read-only - you could QI for a modifiable // list. We gain some perf by doing this. We believe this is acceptable. @@ -74,7 +72,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool IndexOf(T value, out uint index) - [SecurityCritical] internal bool IndexOf<T>(T value, out uint index) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -91,7 +88,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void SetAt(uint index, T value) - [SecurityCritical] internal void SetAt<T>(uint index, T value) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -108,7 +104,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void InsertAt(uint index, T value) - [SecurityCritical] internal void InsertAt<T>(uint index, T value) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -130,7 +125,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void RemoveAt(uint index) - [SecurityCritical] internal void RemoveAt<T>(uint index) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -149,7 +143,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Append(T value) - [SecurityCritical] internal void Append<T>(T value) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -157,7 +150,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void RemoveAtEnd() - [SecurityCritical] internal void RemoveAtEnd<T>() { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -173,7 +165,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - [SecurityCritical] internal void Clear<T>() { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -181,7 +172,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // uint GetMany(uint startIndex, T[] items) - [SecurityCritical] internal uint GetMany<T>(uint startIndex, T[] items) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -189,7 +179,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void ReplaceAll(T[] items) - [SecurityCritical] internal void ReplaceAll<T>(T[] items) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); @@ -212,7 +201,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs index 3e93428d26..2d08cab0ee 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs @@ -33,16 +33,15 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private Type m_type; - [SecurityCritical] internal ManagedActivationFactory(Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); // Check whether the type is "exported to WinRT", i.e. it is declared in a managed .winmd and is decorated // with at least one ActivatableAttribute or StaticAttribute. if (!(type is RuntimeType) || !type.IsExportedToWindowsRuntime) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotActivatableViaWindowsRuntime", type), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotActivatableViaWindowsRuntime", type), nameof(type)); m_type = type; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs index 395bef93d5..f11260eb4a 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs @@ -8,6 +8,7 @@ using System; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -29,12 +30,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private MapToCollectionAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // int Count { get } [Pure] - [SecurityCritical] internal int Count<K, V>() { object _this = JitHelpers.UnsafeCast<object>(this); @@ -66,14 +66,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool IsReadOnly { get } - [SecurityCritical] internal bool IsReadOnly<K, V>() { return false; } // void Add(T item) - [SecurityCritical] internal void Add<K, V>(KeyValuePair<K, V> item) { object _this = JitHelpers.UnsafeCast<object>(this); @@ -91,7 +89,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - [SecurityCritical] internal void Clear<K, V>() { object _this = JitHelpers.UnsafeCast<object>(this); @@ -109,7 +106,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Contains(T item) - [SecurityCritical] internal bool Contains<K, V>(KeyValuePair<K, V> item) { object _this = JitHelpers.UnsafeCast<object>(this); @@ -135,14 +131,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void CopyTo(T[] array, int arrayIndex) - [SecurityCritical] internal void CopyTo<K, V>(KeyValuePair<K, V>[] array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); if (array.Length <= arrayIndex && Count<K, V>() > 0) throw new ArgumentException(Environment.GetResourceString("Argument_IndexOutOfArrayBounds")); @@ -160,7 +155,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Remove(T item) - [SecurityCritical] internal bool Remove<K, V>(KeyValuePair<K, V> item) { object _this = JitHelpers.UnsafeCast<object>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs index d7897ced9f..981972ca9f 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs @@ -8,6 +8,7 @@ using System; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -26,15 +27,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private MapToDictionaryAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // V this[K key] { get } - [SecurityCritical] internal V Indexer_Get<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); @@ -43,11 +43,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // V this[K key] { set } - [SecurityCritical] internal void Indexer_Set<K, V>(K key, V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); @@ -56,7 +55,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // ICollection<K> Keys { get } - [SecurityCritical] internal ICollection<K> Keys<K, V>() { IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); @@ -65,7 +63,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // ICollection<V> Values { get } - [SecurityCritical] internal ICollection<V> Values<K, V>() { IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); @@ -75,22 +72,20 @@ namespace System.Runtime.InteropServices.WindowsRuntime // bool ContainsKey(K key) [Pure] - [SecurityCritical] internal bool ContainsKey<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); return _this.HasKey(key); } // void Add(K key, V value) - [SecurityCritical] internal void Add<K, V>(K key, V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); if (ContainsKey<K, V>(key)) throw new ArgumentException(Environment.GetResourceString("Argument_AddingDuplicate")); @@ -102,11 +97,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Remove(TKey key) - [SecurityCritical] internal bool Remove<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); if (!_this.HasKey(key)) @@ -128,11 +122,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool TryGetValue(TKey key, out TValue value) - [SecurityCritical] internal bool TryGetValue<K, V>(K key, out V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); if (!_this.HasKey(key)) diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapViewToReadOnlyCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapViewToReadOnlyCollectionAdapter.cs index 58427fbd71..a3715da0b0 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapViewToReadOnlyCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapViewToReadOnlyCollectionAdapter.cs @@ -8,6 +8,7 @@ using System; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -29,12 +30,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private MapViewToReadOnlyCollectionAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // int Count { get } [Pure] - [SecurityCritical] internal int Count<K, V>() { object _this = JitHelpers.UnsafeCast<object>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs index b8cd65efa6..4380369754 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs @@ -22,30 +22,25 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal static class UnsafeNativeMethods { [DllImport("api-ms-win-core-winrt-error-l1-1-1.dll", PreserveSig = false)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] internal static extern IRestrictedErrorInfo GetRestrictedErrorInfo(); [DllImport("api-ms-win-core-winrt-error-l1-1-1.dll")] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool RoOriginateLanguageException(int error, [MarshalAs(UnmanagedType.HString)]string message, IntPtr languageException); [DllImport("api-ms-win-core-winrt-error-l1-1-1.dll", PreserveSig = false)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] internal static extern void RoReportUnhandledError(IRestrictedErrorInfo error); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] internal static unsafe extern int WindowsCreateString([MarshalAs(UnmanagedType.LPWStr)] string sourceString, int length, [Out] IntPtr *hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] internal static unsafe extern int WindowsCreateStringReference(char *sourceString, int length, @@ -53,12 +48,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime [Out] IntPtr *hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] internal static extern int WindowsDeleteString(IntPtr hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] internal static unsafe extern char* WindowsGetStringRawBuffer(IntPtr hstring, [Out] uint *length); } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs index 5dd7d00579..cd3c53ab4e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs @@ -57,15 +57,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // // Support for ToString/GetHashCode/Equals override // - [System.Security.SecurityCritical] [MethodImpl(MethodImplOptions.InternalCall)] internal extern IntPtr GetRedirectedGetHashCodeMD(); - [System.Security.SecurityCritical] [MethodImpl(MethodImplOptions.InternalCall)] internal extern int RedirectGetHashCode(IntPtr pMD); - [System.Security.SecuritySafeCritical] public override int GetHashCode() { IntPtr pMD = GetRedirectedGetHashCodeMD(); @@ -74,15 +71,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return RedirectGetHashCode(pMD); } - [System.Security.SecurityCritical] [MethodImpl(MethodImplOptions.InternalCall)] internal extern IntPtr GetRedirectedToStringMD(); - [System.Security.SecurityCritical] [MethodImpl(MethodImplOptions.InternalCall)] internal extern string RedirectToString(IntPtr pMD); - [System.Security.SecuritySafeCritical] public override string ToString() { // Check whether the type implements IStringable. @@ -102,15 +96,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime { } } - [System.Security.SecurityCritical] [MethodImpl(MethodImplOptions.InternalCall)] internal extern IntPtr GetRedirectedEqualsMD(); - [System.Security.SecurityCritical] [MethodImpl(MethodImplOptions.InternalCall)] internal extern bool RedirectEquals(object obj, IntPtr pMD); - [System.Security.SecuritySafeCritical] public override bool Equals(object obj) { IntPtr pMD = GetRedirectedEqualsMD(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs index 5eeb0afcfc..898f1a68a0 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs @@ -8,6 +8,7 @@ using System; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -26,12 +27,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private VectorToCollectionAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // int Count { get } [Pure] - [SecurityCritical] internal int Count<T>() { IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); @@ -45,14 +45,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool IsReadOnly { get } - [SecurityCritical] internal bool IsReadOnly<T>() { return false; } // void Add(T item) - [SecurityCritical] internal void Add<T>(T item) { IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); @@ -60,7 +58,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Clear() - [SecurityCritical] internal void Clear<T>() { IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); @@ -68,7 +65,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Contains(T item) - [SecurityCritical] internal bool Contains<T>(T item) { IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); @@ -78,14 +74,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void CopyTo(T[] array, int arrayIndex) - [SecurityCritical] internal void CopyTo<T>(T[] array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); if (array.Length <= arrayIndex && Count<T>() > 0) throw new ArgumentException(Environment.GetResourceString("Argument_IndexOutOfArrayBounds")); @@ -104,7 +99,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool Remove(T item) - [SecurityCritical] internal bool Remove<T>(T item) { IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs index f27cc95176..3e3324864d 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs @@ -8,6 +8,7 @@ using System; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -26,33 +27,30 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private VectorToListAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // T this[int index] { get } - [SecurityCritical] internal T Indexer_Get<T>(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); return GetAt(_this, (uint)index); } // T this[int index] { set } - [SecurityCritical] internal void Indexer_Set<T>(int index, T value) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); SetAt(_this, (uint)index, value); } // int IndexOf(T item) - [SecurityCritical] internal int IndexOf<T>(T item) { IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); @@ -72,22 +70,20 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Insert(int index, T item) - [SecurityCritical] internal void Insert<T>(int index, T item) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); InsertAtHelper<T>(_this, (uint)index, item); } // void RemoveAt(int index) - [SecurityCritical] internal void RemoveAt<T>(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); RemoveAtHelper<T>(_this, (uint)index); @@ -107,7 +103,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -125,7 +121,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -143,7 +139,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -161,7 +157,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorViewToReadOnlyCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorViewToReadOnlyCollectionAdapter.cs index 4b4ae5d6fc..6b7785d2dc 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorViewToReadOnlyCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorViewToReadOnlyCollectionAdapter.cs @@ -8,6 +8,7 @@ using System; using System.Security; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -26,12 +27,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { private VectorViewToReadOnlyCollectionAdapter() { - Contract.Assert(false, "This class is never instantiated"); + Debug.Assert(false, "This class is never instantiated"); } // int Count { get } [Pure] - [SecurityCritical] internal int Count<T>() { IVectorView<T> _this = JitHelpers.UnsafeCast<IVectorView<T>>(this); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs index 0d59895bc4..a786880fab 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs @@ -19,7 +19,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime { internal static class WindowsRuntimeBufferHelper { - [SecurityCritical] [DllImport(JitHelpers.QCall)] [SuppressUnmanagedCodeSecurity] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] @@ -27,7 +26,6 @@ internal static class WindowsRuntimeBufferHelper { [FriendAccessAllowed] - [SecurityCritical] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal unsafe static void StoreOverlappedInCCW(Object windowsRuntimeBuffer, NativeOverlapped* overlapped) { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs index 038efd5013..a7ad4912de 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Reflection; using System.Runtime.CompilerServices; @@ -23,15 +24,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime // delegate. It then stores the corresponding token in a dictionary for easy access by RemoveEventHandler // later. Note that the dictionary is indexed by the remove method that will be used for RemoveEventHandler // so the removeMethod given here must match the remove method supplied there exactly. - [SecurityCritical] public static void AddEventHandler<T>(Func<T, EventRegistrationToken> addMethod, Action<EventRegistrationToken> removeMethod, T handler) { if (addMethod == null) - throw new ArgumentNullException("addMethod"); + throw new ArgumentNullException(nameof(addMethod)); if (removeMethod == null) - throw new ArgumentNullException("removeMethod"); + throw new ArgumentNullException(nameof(removeMethod)); Contract.EndContractBlock(); // Managed code allows adding a null event handler, the effect is a no-op. To match this behavior @@ -54,11 +54,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Remove the delegate handler from the Windows Runtime style event registration by looking for // its token, previously stored via AddEventHandler<T> - [SecurityCritical] public static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler) { if (removeMethod == null) - throw new ArgumentNullException("removeMethod"); + throw new ArgumentNullException(nameof(removeMethod)); Contract.EndContractBlock(); // Managed code allows removing a null event handler, the effect is a no-op. To match this behavior @@ -79,11 +78,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime ManagedEventRegistrationImpl.RemoveEventHandler<T>(removeMethod, handler); } - [SecurityCritical] public static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod) { if (removeMethod == null) - throw new ArgumentNullException("removeMethod"); + throw new ArgumentNullException(nameof(removeMethod)); Contract.EndContractBlock(); // Delegate to managed event registration implementation or native event registration implementation @@ -220,7 +218,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime ConditionalWeakTable<object, Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>> s_eventRegistrations = new ConditionalWeakTable<object, Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>>(); - [SecurityCritical] internal static void AddEventHandler<T>(Func<T, EventRegistrationToken> addMethod, Action<EventRegistrationToken> removeMethod, T handler) @@ -280,7 +277,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - [SecurityCritical] internal static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler) { Contract.Requires(removeMethod != null); @@ -322,7 +318,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event unsubscribed for managed instance = " + instance + ", handler = " + handler + ", token = " + token.m_value + "\n"); } - [SecurityCritical] internal static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod) { Contract.Requires(removeMethod != null); @@ -538,11 +533,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime private volatile static MyReaderWriterLock s_eventCacheRWLock = new MyReaderWriterLock(); // Get InstanceKey to use in the cache - [SecuritySafeCritical] private static object GetInstanceKey(Action<EventRegistrationToken> removeMethod) { object target = removeMethod.Target; - Contract.Assert(target == null || Marshal.IsComObject(target), "Must be null or a RCW"); + Debug.Assert(target == null || Marshal.IsComObject(target), "Must be null or a RCW"); if (target == null) return removeMethod.Method.DeclaringType; @@ -550,7 +544,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return (object) Marshal.GetRawIUnknownForComObjectNoAddRef(target); } - [SecurityCritical] internal static void AddEventHandler<T>(Func<T, EventRegistrationToken> addMethod, Action<EventRegistrationToken> removeMethod, T handler) @@ -685,7 +678,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - [SecurityCritical] internal static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler) { object instanceKey = GetInstanceKey(removeMethod); @@ -721,7 +713,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Note that inside TryGetValueWithValueEquality we assumes that any delegate // with the same value equality would have the same hash code object key = registrationTokens.FindEquivalentKeyUnsafe(handler, out tokens); - Contract.Assert((key != null && tokens != null) || (key == null && tokens == null), + Debug.Assert((key != null && tokens != null) || (key == null && tokens == null), "key and tokens must be both null or non-null"); if (tokens == null) { @@ -762,7 +754,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime removeMethod(token); } - [SecurityCritical] internal static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod) { object instanceKey = GetInstanceKey(removeMethod); @@ -908,7 +899,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void ReleaseReaderLock() { EnterMyLock(); - Contract.Assert(owners > 0, "ReleasingReaderLock: releasing lock and no read lock taken"); + Debug.Assert(owners > 0, "ReleasingReaderLock: releasing lock and no read lock taken"); --owners; ExitAndWakeUpAppropriateWaiters(); } @@ -916,7 +907,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void ReleaseWriterLock() { EnterMyLock(); - Contract.Assert(owners == -1, "Calling ReleaseWriterLock when no write lock is held"); + Debug.Assert(owners == -1, "Calling ReleaseWriterLock when no write lock is held"); owners++; ExitAndWakeUpAppropriateWaiters(); } @@ -928,8 +919,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime /// set 'waitEvent' /// </summary> private void LazyCreateEvent(ref EventWaitHandle waitEvent, bool makeAutoResetEvent) { - Contract.Assert(myLock != 0, "Lock must be held"); - Contract.Assert(waitEvent == null, "Wait event must be null"); + Debug.Assert(myLock != 0, "Lock must be held"); + Debug.Assert(waitEvent == null, "Wait event must be null"); ExitMyLock(); EventWaitHandle newEvent; @@ -948,7 +939,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime /// </summary> private void WaitOnEvent(EventWaitHandle waitEvent, ref uint numWaiters, int millisecondsTimeout) { - Contract.Assert(myLock != 0, "Lock must be held"); + Debug.Assert(myLock != 0, "Lock must be held"); waitEvent.Reset(); numWaiters++; @@ -976,7 +967,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime /// </summary> private void ExitAndWakeUpAppropriateWaiters() { - Contract.Assert(myLock != 0, "Lock must be held"); + Debug.Assert(myLock != 0, "Lock must be held"); if (owners == 0 && numWriteWaiters > 0) { @@ -1012,7 +1003,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } private void ExitMyLock() { - Contract.Assert(myLock != 0, "Exiting spin lock that is not held"); + Debug.Assert(myLock != 0, "Exiting spin lock that is not held"); myLock = 0; } }; @@ -1044,7 +1035,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new AggregateException(exceptions.ToArray()); } - [SecurityCritical] internal static unsafe string HStringToString(IntPtr hstring) { Contract.Requires(Environment.IsWinRTSupported); @@ -1092,7 +1082,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime private static bool s_haveBlueErrorApis = true; - [SecurityCritical] private static bool RoOriginateLanguageException(int error, string message, IntPtr languageException) { if (s_haveBlueErrorApis) @@ -1110,7 +1099,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return false; } - [SecurityCritical] private static void RoReportUnhandledError(IRestrictedErrorInfo error) { if (s_haveBlueErrorApis) @@ -1134,7 +1122,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime /// </summary> /// <returns>true if the error was reported, false if not (ie running on Win8)</returns> [FriendAccessAllowed] - [SecuritySafeCritical] internal static bool ReportUnhandledError(Exception e) { // Only report to the WinRT global exception handler in modern apps @@ -1200,14 +1187,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime #if FEATURE_COMINTEROP_WINRT_MANAGED_ACTIVATION // Get an IActivationFactory * for a managed type - [SecurityCritical] internal static IntPtr GetActivationFactoryForType(Type type) { ManagedActivationFactory activationFactory = GetManagedActivationFactory(type); return Marshal.GetComInterfaceForObject(activationFactory, typeof(IActivationFactory)); } - [SecurityCritical] internal static ManagedActivationFactory GetManagedActivationFactory(Type type) { ManagedActivationFactory activationFactory = new ManagedActivationFactory(type); @@ -1224,7 +1209,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime // holds the IWinRTClassActivator* that is used for the process private static IntPtr s_pClassActivator = IntPtr.Zero; - [SecurityCritical] internal static IntPtr GetClassActivatorForApplication(string appBase) { if (s_pClassActivator == IntPtr.Zero) @@ -1268,11 +1252,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime // factories from other apartments and make transiton to those apartments and cause // deadlocks and create objects in incorrect apartments // - [SecurityCritical] public static IActivationFactory GetActivationFactory(Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (type.IsWindowsRuntimeObject && type.IsImport) { @@ -1291,14 +1274,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime // HSTRING marshaling methods: - [SecurityCritical] public static IntPtr StringToHString(String s) { if (!Environment.IsWinRTSupported) throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); if (s == null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); unsafe { @@ -1309,7 +1291,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - [SecurityCritical] public static String PtrToStringHString(IntPtr ptr) { if (!Environment.IsWinRTSupported) @@ -1320,7 +1301,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return HStringToString(ptr); } - [SecurityCritical] public static void FreeHString(IntPtr ptr) { if (!Environment.IsWinRTSupported) diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs index e2ad203583..9ca959c528 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs @@ -19,18 +19,16 @@ namespace System.Runtime.InteropServices.WindowsRuntime public static class WindowsRuntimeMetadata { // Wrapper for Win8 API RoResolveNamespace with default Windows SDK path as installed .winmd files in %WINDIR%\system32\WinMetadata. - [System.Security.SecurityCritical] public static IEnumerable<string> ResolveNamespace(string namespaceName, IEnumerable<string> packageGraphFilePaths) { return ResolveNamespace(namespaceName, null, packageGraphFilePaths); } // Wrapper for Win8 API RoResolveNamespace. - [System.Security.SecurityCritical] public static IEnumerable<string> ResolveNamespace(string namespaceName, string windowsSdkFilePath, IEnumerable<string> packageGraphFilePaths) { if (namespaceName == null) - throw new ArgumentNullException("namespaceName"); + throw new ArgumentNullException(nameof(namespaceName)); Contract.EndContractBlock(); string[] packageGraphFilePathsArray = null; @@ -58,7 +56,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime return retFileNames; } - [System.Security.SecurityCritical] [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void nResolveNamespace( |