diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs
index 6929c4752ed13..d8eea0900de43 100644
--- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs
+++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/InMemoryAssemblyLoader.cs
@@ -25,7 +25,7 @@ internal static class InMemoryAssemblyLoader
///
/// The native module handle for the assembly.
/// The path to the assembly (as a pointer to a UTF-16 C string).
- public static unsafe void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assemblyPath)
+ public static void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assemblyPath)
{
if (!IsSupported)
throw new NotSupportedException(SR.NotSupported_CppCli);
@@ -37,7 +37,7 @@ public static unsafe void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assem
// It is intentionally left in the product, so developers get a warning when trimming an app which enabled `Internal.Runtime.InteropServices.InMemoryAssemblyLoader.IsSupported`.
// For runtime build the warning is suppressed in the ILLink.Suppressions.LibraryBuild.xml, but we only want to suppress it if the feature is enabled (IsSupported is true).
// The call is extracted into a separate method which is the sole target of the suppression.
- private static unsafe void LoadInMemoryAssemblyInContextWhenSupported(IntPtr moduleHandle, IntPtr assemblyPath)
+ private static void LoadInMemoryAssemblyInContextWhenSupported(IntPtr moduleHandle, IntPtr assemblyPath)
{
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
LoadInMemoryAssemblyInContextImpl(moduleHandle, assemblyPath);
@@ -54,7 +54,7 @@ private static unsafe void LoadInMemoryAssemblyInContextWhenSupported(IntPtr mod
[UnmanagedCallersOnly]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "The same C++/CLI feature switch applies to LoadInMemoryAssembly and this function. We rely on the warning from LoadInMemoryAssembly.")]
- public static unsafe void LoadInMemoryAssemblyInContext(IntPtr moduleHandle, IntPtr assemblyPath, IntPtr loadContext)
+ public static void LoadInMemoryAssemblyInContext(IntPtr moduleHandle, IntPtr assemblyPath, IntPtr loadContext)
{
if (!IsSupported)
throw new NotSupportedException(SR.NotSupported_CppCli);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs b/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
index 608412751f8fb..7beb15f81ccc2 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
@@ -136,7 +136,7 @@ public int GetRemainingCount()
}
// Gets the type of the current arg, does NOT advance the iterator
- public unsafe RuntimeTypeHandle GetNextArgType()
+ public RuntimeTypeHandle GetNextArgType()
{
return RuntimeTypeHandle.FromIntPtr(GetNextArgType(ThisPtr));
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
index 01743710316e7..7bb38b45723c9 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
@@ -109,7 +109,7 @@ private static CorElementType GetNormalizedIntegralArrayElementType(CorElementTy
// instance & might fail when called from within a CER, or if the
// reliable flag is true, it will either always succeed or always
// throw an exception with no side effects.
- private static unsafe void CopySlow(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, ArrayAssignType assignType)
+ private static void CopySlow(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, ArrayAssignType assignType)
{
Debug.Assert(sourceArray.Rank == destinationArray.Rank);
@@ -605,7 +605,7 @@ private unsafe void InternalSetValue(object? value, nint flattenedIndex)
public long LongLength => (long)NativeLength;
- public unsafe int Rank
+ public int Rank
{
get
{
@@ -615,7 +615,7 @@ public unsafe int Rank
}
[Intrinsic]
- public unsafe int GetLength(int dimension)
+ public int GetLength(int dimension)
{
int rank = RuntimeHelpers.GetMultiDimensionalArrayRank(this);
if (rank == 0 && dimension == 0)
@@ -628,7 +628,7 @@ public unsafe int GetLength(int dimension)
}
[Intrinsic]
- public unsafe int GetUpperBound(int dimension)
+ public int GetUpperBound(int dimension)
{
int rank = RuntimeHelpers.GetMultiDimensionalArrayRank(this);
if (rank == 0 && dimension == 0)
@@ -642,7 +642,7 @@ public unsafe int GetUpperBound(int dimension)
}
[Intrinsic]
- public unsafe int GetLowerBound(int dimension)
+ public int GetLowerBound(int dimension)
{
int rank = RuntimeHelpers.GetMultiDimensionalArrayRank(this);
if (rank == 0 && dimension == 0)
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs
index ad960b1bb4563..7d53f6b24f6e7 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs
@@ -302,7 +302,7 @@ internal static unsafe MarshalAsAttribute GetMarshalAs(ConstArray nativeType, Ru
#region Constructor
[MethodImpl(MethodImplOptions.InternalCall)]
- private static extern unsafe IntPtr GetMetadataImport(RuntimeModule module);
+ private static extern IntPtr GetMetadataImport(RuntimeModule module);
internal MetadataImport(RuntimeModule module)
{
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
index e9cd2153596de..cf27a2aaba39d 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
@@ -9,7 +9,7 @@
namespace System.Reflection
{
- internal sealed unsafe class RtFieldInfo : RuntimeFieldInfo, IRuntimeFieldInfo
+ internal sealed class RtFieldInfo : RuntimeFieldInfo, IRuntimeFieldInfo
{
#region Private Data Members
// aggressive caching
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
index 24dd89c211317..61a4163529e0d 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
@@ -8,7 +8,7 @@
namespace System.Reflection
{
- internal sealed unsafe class RuntimeParameterInfo : ParameterInfo
+ internal sealed class RuntimeParameterInfo : ParameterInfo
{
#region Static Members
internal static ParameterInfo[] GetParameters(IRuntimeMethodInfo method, MemberInfo member, Signature sig)
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs
index fad67c99946a9..a441e4890f9df 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs
@@ -489,7 +489,7 @@ private static void StelemRef_Helper_NoCacheLookup(ref object? element, void* el
}
[DebuggerHidden]
- private static unsafe void ArrayTypeCheck(object obj, Array array)
+ private static void ArrayTypeCheck(object obj, Array array)
{
Debug.Assert(obj != null);
@@ -507,7 +507,7 @@ private static unsafe void ArrayTypeCheck(object obj, Array array)
[DebuggerHidden]
[MethodImpl(MethodImplOptions.NoInlining)]
- private static unsafe void ArrayTypeCheck_Helper(object obj, void* elementType)
+ private static void ArrayTypeCheck_Helper(object obj, void* elementType)
{
Debug.Assert(obj != null);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericsHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericsHelpers.cs
index aeba3370b3c0b..3d719604f4337 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericsHelpers.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericsHelpers.cs
@@ -28,7 +28,7 @@ public static IntPtr Method(IntPtr methodHnd, IntPtr signature)
}
[DebuggerHidden]
- public static unsafe IntPtr MethodWithSlotAndModule(IntPtr methodHnd, GenericHandleArgs * pArgs)
+ public static IntPtr MethodWithSlotAndModule(IntPtr methodHnd, GenericHandleArgs * pArgs)
{
return GenericHandleWorker(methodHnd, IntPtr.Zero, pArgs->signature, pArgs->dictionaryIndexAndSlot, pArgs->module);
}
@@ -40,7 +40,7 @@ public static IntPtr Class(IntPtr classHnd, IntPtr signature)
}
[DebuggerHidden]
- public static unsafe IntPtr ClassWithSlotAndModule(IntPtr classHnd, GenericHandleArgs * pArgs)
+ public static IntPtr ClassWithSlotAndModule(IntPtr classHnd, GenericHandleArgs * pArgs)
{
return GenericHandleWorker(IntPtr.Zero, classHnd, pArgs->signature, pArgs->dictionaryIndexAndSlot, pArgs->module);
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
index 994cb70b5079b..2fcc827abcf05 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
@@ -286,7 +286,7 @@ static int GetHashCodeWorker(object? o)
}
[MethodImpl(MethodImplOptions.InternalCall)]
- private static extern unsafe bool ContentEquals(object o1, object o2);
+ private static extern bool ContentEquals(object o1, object o2);
[Obsolete("OffsetToStringData has been deprecated. Use string.GetPinnableReference() instead.")]
public static int OffsetToStringData
@@ -414,7 +414,7 @@ internal static unsafe ushort GetElementSize(this Array array)
// Returns pointer to the multi-dimensional array bounds.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe ref int GetMultiDimensionalArrayBounds(Array array)
+ internal static ref int GetMultiDimensionalArrayBounds(Array array)
{
Debug.Assert(GetMultiDimensionalArrayRank(array) > 0);
// See comment on RawArrayData for details
@@ -553,7 +553,7 @@ private static unsafe void DispatchTailCalls(
/// The specified type handle is null.
/// The specified type cannot have a boxed instance of itself created.
/// The passed in type is a by-ref-like type.
- public static unsafe object? Box(ref byte target, RuntimeTypeHandle type)
+ public static object? Box(ref byte target, RuntimeTypeHandle type)
{
if (type.IsNullHandle())
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.type);
@@ -574,7 +574,7 @@ private static unsafe void DispatchTailCalls(
///
/// This API returns the same value as for the type that represents.
///
- public static unsafe int SizeOf(RuntimeTypeHandle type)
+ public static int SizeOf(RuntimeTypeHandle type)
{
if (type.IsNullHandle())
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.type);
@@ -951,11 +951,11 @@ internal static ref byte MaskStaticsPointer(ref byte staticsPtr)
}
}
- internal unsafe MethodTable* _methodTable;
+ internal MethodTable* _methodTable;
}
[StructLayout(LayoutKind.Sequential)]
- internal unsafe ref struct GenericsStaticsInfo
+ internal ref struct GenericsStaticsInfo
{
// Pointer to field descs for statics
internal IntPtr _pFieldDescs;
@@ -963,7 +963,7 @@ internal unsafe ref struct GenericsStaticsInfo
}
[StructLayout(LayoutKind.Sequential)]
- internal unsafe ref struct ThreadStaticsInfo
+ internal ref struct ThreadStaticsInfo
{
internal int _nonGCTlsIndex;
internal int _gcTlsIndex;
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/VirtualDispatchHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/VirtualDispatchHelpers.cs
index 131a39d4a816b..c9564984c38b4 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/VirtualDispatchHelpers.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/VirtualDispatchHelpers.cs
@@ -63,7 +63,7 @@ private struct VirtualFunctionPointerArgs
[MethodImpl(MethodImplOptions.NoInlining)]
[DebuggerHidden]
- private static unsafe IntPtr VirtualFunctionPointerSlow(object obj, IntPtr classHandle, IntPtr methodHandle)
+ private static IntPtr VirtualFunctionPointerSlow(object obj, IntPtr classHandle, IntPtr methodHandle)
{
IntPtr result = ResolveVirtualFunctionPointer(ObjectHandleOnStack.Create(ref obj), classHandle, methodHandle);
s_virtualFunctionPointerCache.TrySet(new VirtualResolutionData(RuntimeHelpers.GetMethodTable(obj), classHandle, methodHandle), result);
@@ -72,7 +72,7 @@ private static unsafe IntPtr VirtualFunctionPointerSlow(object obj, IntPtr class
}
[DebuggerHidden]
- private static unsafe IntPtr VirtualFunctionPointer(object obj, IntPtr classHandle, IntPtr methodHandle)
+ private static IntPtr VirtualFunctionPointer(object obj, IntPtr classHandle, IntPtr methodHandle)
{
if (s_virtualFunctionPointerCache.TryGet(new VirtualResolutionData(RuntimeHelpers.GetMethodTable(obj), classHandle, methodHandle), out IntPtr result))
{
@@ -82,7 +82,7 @@ private static unsafe IntPtr VirtualFunctionPointer(object obj, IntPtr classHand
}
[DebuggerHidden]
- private static unsafe IntPtr VirtualFunctionPointer_Dynamic(object obj, ref VirtualFunctionPointerArgs virtualFunctionPointerArgs)
+ private static IntPtr VirtualFunctionPointer_Dynamic(object obj, ref VirtualFunctionPointerArgs virtualFunctionPointerArgs)
{
IntPtr classHandle = virtualFunctionPointerArgs.classHnd;
IntPtr methodHandle = virtualFunctionPointerArgs.methodHnd;
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
index 7e98a13fcc539..c7c78a7325f99 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
@@ -39,7 +39,7 @@ public abstract partial class ComWrappers
/// it is important for the caller to understand the COM object may have apartment affinity and therefore
/// if the current thread is not in the correct apartment or the COM object is not a proxy this call may fail.
///
- public static unsafe bool TryGetComInstance(object obj, out IntPtr unknown)
+ public static bool TryGetComInstance(object obj, out IntPtr unknown)
{
if (obj == null)
{
@@ -61,7 +61,7 @@ public static unsafe bool TryGetComInstance(object obj, out IntPtr unknown)
/// An unmanaged wrapper
/// A managed object
/// True if the wrapper was resolved to a managed object, otherwise false.
- public static unsafe bool TryGetObject(IntPtr unknown, [NotNullWhen(true)] out object? obj)
+ public static bool TryGetObject(IntPtr unknown, [NotNullWhen(true)] out object? obj)
{
obj = null;
if (unknown == IntPtr.Zero)
diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
index 4bc9b32f20ca3..9717cac05d4df 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
@@ -643,7 +643,7 @@ internal string ConstructName(TypeNameFormatFlags formatFlags)
// Since the returned string is a pointer into metadata, the caller should
// ensure the passed in type is alive for at least as long as returned result is
// needed.
- internal static unsafe MdUtf8String GetUtf8Name(RuntimeType type)
+ internal static MdUtf8String GetUtf8Name(RuntimeType type)
{
TypeHandle th = type.GetNativeTypeHandle();
if (th.IsTypeDesc || th.AsMethodTable()->IsArray)
@@ -673,7 +673,7 @@ internal static bool CanCastTo(RuntimeType type, RuntimeType target)
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeTypeHandle_GetDeclaringTypeHandle")]
private static partial IntPtr GetDeclaringTypeHandle(IntPtr typeHandle);
- internal static unsafe RuntimeType? GetDeclaringType(RuntimeType type)
+ internal static RuntimeType? GetDeclaringType(RuntimeType type)
{
IntPtr retTypeHandle = IntPtr.Zero;
TypeHandle typeHandle = type.GetNativeTypeHandle();
diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
index ea88559efeceb..67c83e3867151 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
@@ -863,7 +863,7 @@ private unsafe void PopulateRtFields(Filter filter, RuntimeType declaringType, r
}
}
- private unsafe void PopulateRtFields(Filter filter,
+ private void PopulateRtFields(Filter filter,
ReadOnlySpan fieldHandles, RuntimeType declaringType, ref ListBuilder list)
{
Debug.Assert(declaringType != null);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs
index 3c9c08b7c0e81..2d3ef99b3176c 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs
@@ -504,7 +504,7 @@ internal static unsafe void ClearNative(IntPtr pVariant)
internal sealed class HandleMarshaler
{
- internal static unsafe IntPtr ConvertSafeHandleToNative(SafeHandle? handle, ref CleanupWorkListElement? cleanupWorkList)
+ internal static IntPtr ConvertSafeHandleToNative(SafeHandle? handle, ref CleanupWorkListElement? cleanupWorkList)
{
if (Unsafe.IsNullRef(ref cleanupWorkList))
{
@@ -516,12 +516,12 @@ internal static unsafe IntPtr ConvertSafeHandleToNative(SafeHandle? handle, ref
return StubHelpers.AddToCleanupList(ref cleanupWorkList, handle);
}
- internal static unsafe void ThrowSafeHandleFieldChanged()
+ internal static void ThrowSafeHandleFieldChanged()
{
throw new NotSupportedException(SR.Interop_Marshal_CannotCreateSafeHandleField);
}
- internal static unsafe void ThrowCriticalHandleFieldChanged()
+ internal static void ThrowCriticalHandleFieldChanged()
{
throw new NotSupportedException(SR.Interop_Marshal_CannotCreateCriticalHandleField);
}
@@ -797,7 +797,7 @@ internal static void ClearNative(IntPtr pMarshalState, in object pManagedHome, I
internal static unsafe partial class MngdRefCustomMarshaler
{
- internal static unsafe void ConvertContentsToNative(ICustomMarshaler marshaler, in object pManagedHome, IntPtr* pNativeHome)
+ internal static void ConvertContentsToNative(ICustomMarshaler marshaler, in object pManagedHome, IntPtr* pNativeHome)
{
// COMPAT: We never pass null to MarshalManagedToNative.
if (pManagedHome is null)
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Threading/WaitHandle.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Threading/WaitHandle.CoreCLR.cs
index a9fc4d8b2a045..a63096dc84941 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Threading/WaitHandle.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Threading/WaitHandle.CoreCLR.cs
@@ -11,7 +11,7 @@ public abstract partial class WaitHandle
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "WaitHandle_WaitOneCore")]
private static partial int WaitOneCore(IntPtr waitHandle, int millisecondsTimeout, [MarshalAs(UnmanagedType.Bool)] bool useTrivialWaits);
- private static unsafe int WaitMultipleIgnoringSyncContextCore(ReadOnlySpan waitHandles, bool waitAll, int millisecondsTimeout)
+ private static int WaitMultipleIgnoringSyncContextCore(ReadOnlySpan waitHandles, bool waitAll, int millisecondsTimeout)
=> WaitMultipleIgnoringSyncContext(waitHandles, waitHandles.Length, waitAll, millisecondsTimeout);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "WaitHandle_WaitMultipleIgnoringSyncContext")]
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Variant.cs b/src/coreclr/System.Private.CoreLib/src/System/Variant.cs
index 3e8d4f662046c..ce2777493076b 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Variant.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Variant.cs
@@ -35,7 +35,7 @@ internal static ComVariant GetIUnknownOrIDispatchFromObject(object? obj)
return pUnk == IntPtr.Zero ? null : Marshal.GetObjectForIUnknown(pUnk);
}
- private static unsafe object? ConvertWrappedObject(object? wrapped)
+ private static object? ConvertWrappedObject(object? wrapped)
{
// Historically, for UnknownWrapper and DispatchWrapper, the wrapped object is passed
// into Variant.SetFieldsObject, and the result set in objRef field is used for
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
index 828c6f7a58d9a..0a3f3ab9d0174 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
@@ -148,7 +148,7 @@ private struct OSCONTEXT
{
}
- internal static unsafe void* PointerAlign(void* ptr, int alignmentInBytes)
+ internal static void* PointerAlign(void* ptr, int alignmentInBytes)
{
int alignMask = alignmentInBytes - 1;
#if TARGET_64BIT
@@ -205,7 +205,7 @@ private static void OnUnhandledExceptionViaClassLib(object exception)
}
[MethodImpl(MethodImplOptions.NoInlining)]
- internal static unsafe void UnhandledExceptionFailFastViaClasslib(
+ internal static void UnhandledExceptionFailFastViaClasslib(
RhFailFastReason reason, object unhandledException, IntPtr classlibAddress, ref ExInfo exInfo)
{
#if NATIVEAOT
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CMS_RECIPIENT_INFO.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CMS_RECIPIENT_INFO.cs
index c81aad358ed37..d29fc359e56a3 100644
--- a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CMS_RECIPIENT_INFO.cs
+++ b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CMS_RECIPIENT_INFO.cs
@@ -20,7 +20,7 @@ internal unsafe struct CMSG_CMS_RECIPIENT_INFO
//
private void* pRecipientInfo; // Do NOT add an underscore - this name still maps to a C++ Win32 header definition.
- internal unsafe CMSG_KEY_TRANS_RECIPIENT_INFO* KeyTrans
+ internal CMSG_KEY_TRANS_RECIPIENT_INFO* KeyTrans
{
get
{
@@ -29,7 +29,7 @@ internal unsafe CMSG_KEY_TRANS_RECIPIENT_INFO* KeyTrans
}
}
- internal unsafe CMSG_KEY_AGREE_RECIPIENT_INFO* KeyAgree
+ internal CMSG_KEY_AGREE_RECIPIENT_INFO* KeyAgree
{
get
{
diff --git a/src/libraries/Common/src/Interop/Windows/Interop.OBJECT_ATTRIBUTES.cs b/src/libraries/Common/src/Interop/Windows/Interop.OBJECT_ATTRIBUTES.cs
index f0399f8215308..f3a8d10452fca 100644
--- a/src/libraries/Common/src/Interop/Windows/Interop.OBJECT_ATTRIBUTES.cs
+++ b/src/libraries/Common/src/Interop/Windows/Interop.OBJECT_ATTRIBUTES.cs
@@ -43,7 +43,7 @@ internal unsafe struct OBJECT_ATTRIBUTES
///
/// Equivalent of InitializeObjectAttributes macro with the exception that you can directly set SQOS.
///
- public unsafe OBJECT_ATTRIBUTES(UNICODE_STRING* objectName, ObjectAttributes attributes, IntPtr rootDirectory, SECURITY_QUALITY_OF_SERVICE* securityQualityOfService = null)
+ public OBJECT_ATTRIBUTES(UNICODE_STRING* objectName, ObjectAttributes attributes, IntPtr rootDirectory, SECURITY_QUALITY_OF_SERVICE* securityQualityOfService = null)
{
Length = (uint)sizeof(OBJECT_ATTRIBUTES);
RootDirectory = rootDirectory;
diff --git a/src/libraries/Common/src/Interop/Windows/Interop.SECURITY_QUALITY_OF_SERVICE.cs b/src/libraries/Common/src/Interop/Windows/Interop.SECURITY_QUALITY_OF_SERVICE.cs
index 6a0f0d4795c43..db2d5e01696ae 100644
--- a/src/libraries/Common/src/Interop/Windows/Interop.SECURITY_QUALITY_OF_SERVICE.cs
+++ b/src/libraries/Common/src/Interop/Windows/Interop.SECURITY_QUALITY_OF_SERVICE.cs
@@ -15,7 +15,7 @@ internal unsafe struct SECURITY_QUALITY_OF_SERVICE
public ContextTrackingMode ContextTrackingMode;
public BOOLEAN EffectiveOnly;
- public unsafe SECURITY_QUALITY_OF_SERVICE(ImpersonationLevel impersonationLevel, ContextTrackingMode contextTrackingMode, bool effectiveOnly)
+ public SECURITY_QUALITY_OF_SERVICE(ImpersonationLevel impersonationLevel, ContextTrackingMode contextTrackingMode, bool effectiveOnly)
{
Length = (uint)sizeof(SECURITY_QUALITY_OF_SERVICE);
ImpersonationLevel = impersonationLevel;
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.REPARSE_DATA_BUFFER.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.REPARSE_DATA_BUFFER.cs
index dbfc7c33d7e50..5bd60dff14b92 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.REPARSE_DATA_BUFFER.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.REPARSE_DATA_BUFFER.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
using System.Runtime.InteropServices;
internal static partial class Interop
@@ -15,7 +14,7 @@ internal static partial class Kernel32
// https://msdn.microsoft.com/library/windows/hardware/ff552012.aspx
[StructLayout(LayoutKind.Sequential)]
- internal unsafe struct SymbolicLinkReparseBuffer
+ internal struct SymbolicLinkReparseBuffer
{
internal uint ReparseTag;
internal ushort ReparseDataLength;
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.STORAGE_READ_CAPACITY.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.STORAGE_READ_CAPACITY.cs
index cb6913fa9d114..edc294d34fa25 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.STORAGE_READ_CAPACITY.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.STORAGE_READ_CAPACITY.cs
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
using System.Runtime.InteropServices;
internal static partial class Interop
@@ -10,7 +9,7 @@ internal static partial class Kernel32
{
// https://learn.microsoft.com/windows/win32/devio/storage-read-capacity
[StructLayout(LayoutKind.Sequential)]
- internal unsafe struct STORAGE_READ_CAPACITY
+ internal struct STORAGE_READ_CAPACITY
{
internal uint Version;
internal uint Size;
diff --git a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.FILE_FULL_DIR_INFORMATION.cs b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.FILE_FULL_DIR_INFORMATION.cs
index edf38440f38d9..e54a4e5aee1f7 100644
--- a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.FILE_FULL_DIR_INFORMATION.cs
+++ b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.FILE_FULL_DIR_INFORMATION.cs
@@ -54,7 +54,7 @@ public struct FILE_FULL_DIR_INFORMATION
public uint EaSize;
private char _fileName;
- public unsafe ReadOnlySpan FileName => MemoryMarshal.CreateReadOnlySpan(ref _fileName, (int)FileNameLength / sizeof(char));
+ public ReadOnlySpan FileName => MemoryMarshal.CreateReadOnlySpan(ref _fileName, (int)FileNameLength / sizeof(char));
///
/// Gets the next info pointer or null if there are no more.
diff --git a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.DumpBuffer.cs b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.DumpBuffer.cs
index 522436249dad4..3de4f727df5c3 100644
--- a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.DumpBuffer.cs
+++ b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.DumpBuffer.cs
@@ -35,7 +35,7 @@ public static void DumpBuffer(object? thisOrContextObject, ReadOnlySpan bu
Log.DumpBuffer(IdOf(thisOrContextObject), memberName, buffer.Slice(0, Math.Min(buffer.Length, MaxDumpSize)).ToArray());
[Event(DumpArrayEventId, Level = EventLevel.Verbose, Keywords = Keywords.Debug)]
- private unsafe void DumpBuffer(string thisOrContextObject, string? memberName, byte[] buffer) =>
+ private void DumpBuffer(string thisOrContextObject, string? memberName, byte[] buffer) =>
WriteEvent(DumpArrayEventId, thisOrContextObject, memberName ?? MissingMember, buffer);
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern",
diff --git a/src/libraries/Common/src/System/Net/SocketAddressPal.Windows.cs b/src/libraries/Common/src/System/Net/SocketAddressPal.Windows.cs
index a563675dab62f..828f47a053ca6 100644
--- a/src/libraries/Common/src/System/Net/SocketAddressPal.Windows.cs
+++ b/src/libraries/Common/src/System/Net/SocketAddressPal.Windows.cs
@@ -69,7 +69,7 @@ public static void SetIPv6Address(Span buffer, Span address, uint sc
address.CopyTo(buffer.Slice(8));
}
- public static unsafe void Clear(Span buffer)
+ public static void Clear(Span buffer)
{
AddressFamily family = GetAddressFamily(buffer);
buffer.Clear();
diff --git a/src/libraries/Common/src/System/Number.Formatting.Common.cs b/src/libraries/Common/src/System/Number.Formatting.Common.cs
index da0d7209ab307..37734e001ad94 100644
--- a/src/libraries/Common/src/System/Number.Formatting.Common.cs
+++ b/src/libraries/Common/src/System/Number.Formatting.Common.cs
@@ -52,7 +52,7 @@ internal static partial class Number
"(#)", "-#", "- #", "#-", "# -",
];
- internal static unsafe char ParseFormatSpecifier(ReadOnlySpan format, out int digits)
+ internal static char ParseFormatSpecifier(ReadOnlySpan format, out int digits)
{
char c = default;
if (format.Length > 0)
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
index 400d16af590bc..54bd56a30bdeb 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
@@ -1225,7 +1225,7 @@ public void SetValue(string? name, object value)
SetValue(name, value, RegistryValueKind.Unknown);
}
- public unsafe void SetValue(string? name, object value, RegistryValueKind valueKind)
+ public void SetValue(string? name, object value, RegistryValueKind valueKind)
{
ArgumentNullException.ThrowIfNull(value);
diff --git a/src/libraries/System.Collections/src/System/Collections/BitArray.cs b/src/libraries/System.Collections/src/System/Collections/BitArray.cs
index 7de69a92cb4f4..1fd6e46490ebf 100644
--- a/src/libraries/System.Collections/src/System/Collections/BitArray.cs
+++ b/src/libraries/System.Collections/src/System/Collections/BitArray.cs
@@ -115,7 +115,7 @@ public BitArray(byte[] bytes)
_version = 0;
}
- public unsafe BitArray(bool[] values)
+ public BitArray(bool[] values)
{
ArgumentNullException.ThrowIfNull(values);
@@ -312,7 +312,7 @@ public void SetAll(bool value)
** Exceptions: ArgumentException if value == null or
** value.Length != this.Length.
=========================================================================*/
- public unsafe BitArray And(BitArray value)
+ public BitArray And(BitArray value)
{
ArgumentNullException.ThrowIfNull(value);
@@ -385,7 +385,7 @@ public unsafe BitArray And(BitArray value)
** Exceptions: ArgumentException if value == null or
** value.Length != this.Length.
=========================================================================*/
- public unsafe BitArray Or(BitArray value)
+ public BitArray Or(BitArray value)
{
ArgumentNullException.ThrowIfNull(value);
@@ -458,7 +458,7 @@ public unsafe BitArray Or(BitArray value)
** Exceptions: ArgumentException if value == null or
** value.Length != this.Length.
=========================================================================*/
- public unsafe BitArray Xor(BitArray value)
+ public BitArray Xor(BitArray value)
{
ArgumentNullException.ThrowIfNull(value);
@@ -531,7 +531,7 @@ public unsafe BitArray Xor(BitArray value)
** off/false. Off/false bit values are turned on/true. The current instance
** is updated and returned.
=========================================================================*/
- public unsafe BitArray Not()
+ public BitArray Not()
{
// This method uses unsafe code to manipulate data in the BitArray. To avoid issues with
// buggy code concurrently mutating this instance in a way that could cause memory corruption,
diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
index 24931739c31e6..b408cead90685 100644
--- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
+++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs
@@ -2004,7 +2004,7 @@ public void CopyTo(Span destination)
/// Sets the bytes in 'outBytes' to be random values. outBytes.Length must be either 8 or 16 bytes.
///
///
- internal static unsafe void SetToRandomBytes(Span outBytes)
+ internal static void SetToRandomBytes(Span outBytes)
{
Debug.Assert(outBytes.Length == 16 || outBytes.Length == 8);
RandomNumberGenerator r = RandomNumberGenerator.Current;
diff --git a/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/StackTraceSymbols.cs b/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/StackTraceSymbols.cs
index fa2ee8018ba38..102709b51e3a6 100644
--- a/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/StackTraceSymbols.cs
+++ b/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/StackTraceSymbols.cs
@@ -114,7 +114,7 @@ internal void GetSourceLineInfo(Assembly assembly, string assemblyPath, IntPtr l
/// underlying ConditionalWeakTable doesn't keep the assembly alive, so cached types will be
/// correctly invalidated when the Assembly is unloaded by the GC.
///
- private unsafe MetadataReader? TryGetReader(Assembly assembly, string assemblyPath, IntPtr loadedPeAddress, int loadedPeSize, bool isFileLayout, IntPtr inMemoryPdbAddress, int inMemoryPdbSize)
+ private MetadataReader? TryGetReader(Assembly assembly, string assemblyPath, IntPtr loadedPeAddress, int loadedPeSize, bool isFileLayout, IntPtr inMemoryPdbAddress, int inMemoryPdbSize)
{
if (loadedPeAddress == IntPtr.Zero && assemblyPath == null && inMemoryPdbAddress == IntPtr.Zero)
{
diff --git a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/CborHelpers.netstandard.cs b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/CborHelpers.netstandard.cs
index cfe76086ae58d..c2354ab697ac5 100644
--- a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/CborHelpers.netstandard.cs
+++ b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/CborHelpers.netstandard.cs
@@ -182,7 +182,7 @@ public static void WriteHalfBigEndian(Span destination, ushort value)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe float ReadSingleBigEndian(ReadOnlySpan source)
+ public static float ReadSingleBigEndian(ReadOnlySpan source)
{
return BitConverter.IsLittleEndian ?
Int32BitsToSingle(BinaryPrimitives.ReverseEndianness(MemoryMarshal.Read(source))) :
@@ -190,7 +190,7 @@ public static unsafe float ReadSingleBigEndian(ReadOnlySpan source)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void WriteSingleBigEndian(Span destination, float value)
+ public static void WriteSingleBigEndian(Span destination, float value)
{
if (BitConverter.IsLittleEndian)
{
@@ -212,7 +212,7 @@ public static double ReadDoubleBigEndian(ReadOnlySpan source)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void WriteDoubleBigEndian(Span destination, double value)
+ public static void WriteDoubleBigEndian(Span destination, double value)
{
if (BitConverter.IsLittleEndian)
{
diff --git a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/HalfHelpers.netstandard.cs b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/HalfHelpers.netstandard.cs
index d28b9b6f52728..c4d191be9ad54 100644
--- a/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/HalfHelpers.netstandard.cs
+++ b/src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/HalfHelpers.netstandard.cs
@@ -28,7 +28,7 @@ internal static partial class HalfHelpers
public static double HalfToDouble(ushort value)
=> (double)HalfToFloat(value);
- public static unsafe float HalfToFloat(ushort value)
+ public static float HalfToFloat(ushort value)
{
const ushort ExponentMask = 0x7C00;
const ushort ExponentShift = 10;
diff --git a/src/libraries/System.IO.FileSystem.AccessControl/src/System/IO/FileSystemAclExtensions.cs b/src/libraries/System.IO.FileSystem.AccessControl/src/System/IO/FileSystemAclExtensions.cs
index f1fcfb677b905..c75d9afcf37d0 100644
--- a/src/libraries/System.IO.FileSystem.AccessControl/src/System/IO/FileSystemAclExtensions.cs
+++ b/src/libraries/System.IO.FileSystem.AccessControl/src/System/IO/FileSystemAclExtensions.cs
@@ -290,7 +290,7 @@ private static unsafe SafeFileHandle CreateFileHandle(string fullPath, FileMode
return handle;
- static unsafe SafeFileHandle CreateFileHandleInternal(string fullPath, FileMode mode, FileSystemRights rights, FileShare share, int flagsAndAttributes, Interop.Kernel32.SECURITY_ATTRIBUTES* secAttrs)
+ static SafeFileHandle CreateFileHandleInternal(string fullPath, FileMode mode, FileSystemRights rights, FileShare share, int flagsAndAttributes, Interop.Kernel32.SECURITY_ATTRIBUTES* secAttrs)
{
SafeFileHandle handle;
using (DisableMediaInsertionPrompt.Create())
diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs
index 39940b3c80a03..d7e57ee536723 100644
--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs
+++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs
@@ -86,7 +86,7 @@ private static T CreateDelegate(Func functionPointerWrapper, [NotN
internal unsafe AcceptExDelegate GetAcceptExDelegate(SafeSocketHandle socketHandle)
=> _acceptEx ?? CreateDelegate(ptr => new SocketDelegateHelper(ptr).AcceptEx, ref _acceptEx, socketHandle, "b5367df1cbac11cf95ca00805f48a192");
- internal unsafe GetAcceptExSockaddrsDelegate GetGetAcceptExSockaddrsDelegate(SafeSocketHandle socketHandle)
+ internal GetAcceptExSockaddrsDelegate GetGetAcceptExSockaddrsDelegate(SafeSocketHandle socketHandle)
=> _getAcceptExSockaddrs ?? CreateDelegate(ptr => new SocketDelegateHelper(ptr).GetAcceptExSockaddrs, ref _getAcceptExSockaddrs, socketHandle, "b5367df2cbac11cf95ca00805f48a192");
internal unsafe ConnectExDelegate GetConnectExDelegate(SafeSocketHandle socketHandle)
diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
index b58f19fbad912..4c2b9d54dd7d2 100644
--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
+++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
@@ -3589,7 +3589,7 @@ internal void SetReceivingPacketInformation()
}
}
- internal unsafe void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue, bool silent)
+ internal void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue, bool silent)
{
// WASI is always set to receive PacketInformation
if (OperatingSystem.IsWasi() && optionName == SocketOptionName.PacketInformation)
diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs
index a10e8c0cb2f6b..00354f9de2af4 100644
--- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs
+++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs
@@ -4,14 +4,12 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
namespace Internal.Runtime.CompilerHelpers
{
[StackTraceHidden]
[DebuggerStepThrough]
- internal static unsafe partial class ThrowHelpers
+ internal static partial class ThrowHelpers
{
[DoesNotReturn]
[DebuggerHidden]
diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs
index dee00844a55c7..33d08bf108174 100644
--- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs
+++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs
@@ -110,7 +110,7 @@ public static unsafe int LoadAssemblyAndGetFunctionPointer(IntPtr assemblyPathNa
[UnsupportedOSPlatform("maccatalyst")]
[UnsupportedOSPlatform("tvos")]
[UnmanagedCallersOnly]
- public static unsafe int LoadAssembly(IntPtr assemblyPathNative, IntPtr loadContext, IntPtr reserved)
+ public static int LoadAssembly(IntPtr assemblyPathNative, IntPtr loadContext, IntPtr reserved)
{
if (!IsSupported)
return HostFeatureDisabled;
diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Win32/RegistryKey.cs b/src/libraries/System.Private.CoreLib/src/Internal/Win32/RegistryKey.cs
index 780599488c5fd..523dc3bc072b0 100644
--- a/src/libraries/System.Private.CoreLib/src/Internal/Win32/RegistryKey.cs
+++ b/src/libraries/System.Private.CoreLib/src/Internal/Win32/RegistryKey.cs
@@ -143,7 +143,7 @@ ref MemoryMarshal.GetReference(name),
return names.ToArray();
}
- public unsafe string[] GetValueNames()
+ public string[] GetValueNames()
{
var names = new List();
diff --git a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
index 91b863e22f7a5..6e5cc39b0ae8a 100644
--- a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
+++ b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
@@ -36,7 +36,7 @@ internal bool TryGetCachedLength(out long cachedLength)
return _lengthCanBeCached && cachedLength >= 0;
}
- internal static unsafe SafeFileHandle Open(string fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, long preallocationSize, UnixFileMode? unixCreateMode = null)
+ internal static SafeFileHandle Open(string fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, long preallocationSize, UnixFileMode? unixCreateMode = null)
{
Debug.Assert(!unixCreateMode.HasValue);
diff --git a/src/libraries/System.Private.CoreLib/src/System/ArgumentNullException.cs b/src/libraries/System.Private.CoreLib/src/System/ArgumentNullException.cs
index 8094b882ef548..36245853367bd 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ArgumentNullException.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ArgumentNullException.cs
@@ -84,7 +84,7 @@ public static unsafe void ThrowIfNull([NotNull] void* argument, [CallerArgumentE
/// Throws an if is null.
/// The pointer argument to validate as non-null.
/// The name of the parameter with which corresponds.
- internal static unsafe void ThrowIfNull(IntPtr argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
+ internal static void ThrowIfNull(IntPtr argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument == IntPtr.Zero)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs b/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs
index 24069608615fb..0fcd264414fe2 100644
--- a/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs
@@ -892,7 +892,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// The number to convert.
/// A 64-bit signed integer whose bits are identical to .
[Intrinsic]
- public static unsafe long DoubleToInt64Bits(double value) => Unsafe.BitCast(value);
+ public static long DoubleToInt64Bits(double value) => Unsafe.BitCast(value);
///
/// Converts the specified 64-bit signed integer to a double-precision floating point number.
@@ -900,7 +900,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// The number to convert.
/// A double-precision floating point number whose bits are identical to .
[Intrinsic]
- public static unsafe double Int64BitsToDouble(long value) => Unsafe.BitCast(value);
+ public static double Int64BitsToDouble(long value) => Unsafe.BitCast(value);
///
/// Converts the specified single-precision floating point number to a 32-bit signed integer.
@@ -908,7 +908,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// The number to convert.
/// A 32-bit signed integer whose bits are identical to .
[Intrinsic]
- public static unsafe int SingleToInt32Bits(float value) => Unsafe.BitCast(value);
+ public static int SingleToInt32Bits(float value) => Unsafe.BitCast(value);
///
/// Converts the specified 32-bit signed integer to a single-precision floating point number.
@@ -916,7 +916,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// The number to convert.
/// A single-precision floating point number whose bits are identical to .
[Intrinsic]
- public static unsafe float Int32BitsToSingle(int value) => Unsafe.BitCast(value);
+ public static float Int32BitsToSingle(int value) => Unsafe.BitCast(value);
///
/// Converts the specified half-precision floating point number to a 16-bit signed integer.
@@ -924,7 +924,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// The number to convert.
/// A 16-bit signed integer whose bits are identical to .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe short HalfToInt16Bits(Half value) => (short)value._value;
+ public static short HalfToInt16Bits(Half value) => (short)value._value;
///
/// Converts the specified 16-bit signed integer to a half-precision floating point number.
@@ -932,7 +932,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// The number to convert.
/// A half-precision floating point number whose bits are identical to .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Half Int16BitsToHalf(short value) => new Half((ushort)(value));
+ public static Half Int16BitsToHalf(short value) => new Half((ushort)(value));
///
/// Converts the specified double-precision floating point number to a 64-bit unsigned integer.
@@ -941,7 +941,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// A 64-bit unsigned integer whose bits are identical to .
[CLSCompliant(false)]
[Intrinsic]
- public static unsafe ulong DoubleToUInt64Bits(double value) => Unsafe.BitCast(value);
+ public static ulong DoubleToUInt64Bits(double value) => Unsafe.BitCast(value);
///
/// Converts the specified 64-bit unsigned integer to a double-precision floating point number.
@@ -950,7 +950,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// A double-precision floating point number whose bits are identical to .
[CLSCompliant(false)]
[Intrinsic]
- public static unsafe double UInt64BitsToDouble(ulong value) => Unsafe.BitCast(value);
+ public static double UInt64BitsToDouble(ulong value) => Unsafe.BitCast(value);
///
/// Converts the specified single-precision floating point number to a 32-bit unsigned integer.
@@ -959,7 +959,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// A 32-bit unsigned integer whose bits are identical to .
[CLSCompliant(false)]
[Intrinsic]
- public static unsafe uint SingleToUInt32Bits(float value) => Unsafe.BitCast(value);
+ public static uint SingleToUInt32Bits(float value) => Unsafe.BitCast(value);
///
/// Converts the specified 32-bit unsigned integer to a single-precision floating point number.
@@ -968,7 +968,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// A single-precision floating point number whose bits are identical to .
[CLSCompliant(false)]
[Intrinsic]
- public static unsafe float UInt32BitsToSingle(uint value) => Unsafe.BitCast(value);
+ public static float UInt32BitsToSingle(uint value) => Unsafe.BitCast(value);
///
/// Converts the specified half-precision floating point number to a 16-bit unsigned integer.
@@ -977,7 +977,7 @@ public static bool ToBoolean(ReadOnlySpan value)
/// A 16-bit unsigned integer whose bits are identical to .
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe ushort HalfToUInt16Bits(Half value) => value._value;
+ public static ushort HalfToUInt16Bits(Half value) => value._value;
///
/// Converts the specified 16-bit unsigned integer to a half-precision floating point number.
@@ -986,6 +986,6 @@ public static bool ToBoolean(ReadOnlySpan value)
/// A half-precision floating point number whose bits are identical to .
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Half UInt16BitsToHalf(ushort value) => new Half(value);
+ public static Half UInt16BitsToHalf(ushort value) => new Half(value);
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffer.cs b/src/libraries/System.Private.CoreLib/src/System/Buffer.cs
index 30ee85041633d..d3fcd04dcb46f 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Buffer.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Buffer.cs
@@ -13,7 +13,7 @@ public static partial class Buffer
// respecting types. This calls memmove internally. The count and
// offset parameters here are in bytes. If you want to use traditional
// array element indices and counts, use Array.Copy.
- public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
+ public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
{
ArgumentNullException.ThrowIfNull(src);
ArgumentNullException.ThrowIfNull(dst);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
index 8c6ffe9b61c46..89f32fe337f16 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
@@ -38,7 +38,7 @@ internal sealed partial class SharedArrayPool : ArrayPool
private bool _trimCallbackCreated;
/// Allocate a new and try to store it into the array.
- private unsafe SharedArrayPoolPartitions CreatePerCorePartitions(int bucketIndex)
+ private SharedArrayPoolPartitions CreatePerCorePartitions(int bucketIndex)
{
var inst = new SharedArrayPoolPartitions();
return Interlocked.CompareExchange(ref _buckets[bucketIndex], inst, null) ?? inst;
diff --git a/src/libraries/System.Private.CoreLib/src/System/ComAwareWeakReference.cs b/src/libraries/System.Private.CoreLib/src/System/ComAwareWeakReference.cs
index c6e7698c5768c..7d71cd9384652 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ComAwareWeakReference.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ComAwareWeakReference.cs
@@ -41,7 +41,7 @@ internal sealed class ComInfo
}
[MethodImpl(MethodImplOptions.NoInlining)]
- private static unsafe ComInfo? FromObjectSlow(object target)
+ private static ComInfo? FromObjectSlow(object target)
{
IntPtr pComWeakRef = ObjectToComWeakRef(target, out long wrapperId);
if (pComWeakRef == 0)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Convert.cs b/src/libraries/System.Private.CoreLib/src/System/Convert.cs
index 62e4cd8412ab9..0a7e14b01eb25 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Convert.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Convert.cs
@@ -2470,7 +2470,7 @@ public static unsafe bool TryToBase64Chars(ReadOnlySpan bytes, Span
/// The bytes to encode.
/// The destination buffer large enough to handle the encoded chars.
/// The pre-calculated, exact number of chars that will be written.
- private static unsafe void ToBase64CharsLargeNoLineBreaks(ReadOnlySpan bytes, Span chars, int charLengthRequired)
+ private static void ToBase64CharsLargeNoLineBreaks(ReadOnlySpan bytes, Span chars, int charLengthRequired)
{
// For large enough inputs, it's beneficial to use the vectorized UTF8-based Base64 encoding
// and then widen the resulting bytes into chars.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
index 4b6d93f82fe01..722a1343a0537 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs
@@ -154,7 +154,7 @@ private ulong Low64
#region Decimal Math Helpers
- private static unsafe uint GetExponent(float f)
+ private static uint GetExponent(float f)
{
// Based on pulling out the exp from this single struct layout
// typedef struct {
@@ -166,7 +166,7 @@ private static unsafe uint GetExponent(float f)
return (byte)(BitConverter.SingleToUInt32Bits(f) >> 23);
}
- private static unsafe uint GetExponent(double d)
+ private static uint GetExponent(double d)
{
// Based on pulling out the exp from this double struct layout
// typedef struct {
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs
index a25f52aad37f2..36fb1ca5497b4 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs
@@ -55,7 +55,7 @@ internal class EventProvider : IDisposable
[StructLayout(LayoutKind.Sequential)]
public struct EventData
{
- internal unsafe ulong Ptr;
+ internal ulong Ptr;
internal uint Size;
internal uint Reserved;
}
@@ -105,7 +105,7 @@ internal EventProvider(EventProviderType providerType)
///
/// This method registers the provider with the backing tracing mechanism, either ETW or EventPipe.
///
- internal unsafe void Register(Guid id, string name)
+ internal void Register(Guid id, string name)
{
_providerName = name;
_providerId = id;
@@ -940,7 +940,7 @@ internal unsafe int SetInformation(
/// to get the data. The function returns an array of bytes representing the data, the index into that byte array
/// where the data starts, and the command being issued associated with that data.
///
- private unsafe bool TryReadRegistryFilterData(int etwSessionId, out ControllerCommand command, out byte[]? data)
+ private bool TryReadRegistryFilterData(int etwSessionId, out ControllerCommand command, out byte[]? data)
{
command = ControllerCommand.Update;
data = null;
@@ -1320,7 +1320,7 @@ private static int FindNull(byte[] buffer, int idx)
return idx;
}
- protected static unsafe IDictionary? ParseFilterData(byte[]? data)
+ protected static IDictionary? ParseFilterData(byte[]? data)
{
Dictionary? args = null;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
index d280d33c6e3b5..14bac1aebec12 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
@@ -2082,7 +2082,7 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object
Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
"requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
- private unsafe object?[] SerializeEventArgs(int eventId, object?[] args)
+ private object?[] SerializeEventArgs(int eventId, object?[] args)
{
Debug.Assert(m_eventData != null);
TraceLoggingEventTypes eventTypes = m_eventData[eventId].TraceLoggingEventTypes;
@@ -2177,7 +2177,7 @@ private unsafe void WriteToAllListeners(EventWrittenEventArgs eventCallbackArgs,
DispatchToAllListeners(eventCallbackArgs);
}
- internal unsafe void DispatchToAllListeners(EventWrittenEventArgs eventCallbackArgs)
+ internal void DispatchToAllListeners(EventWrittenEventArgs eventCallbackArgs)
{
int eventId = eventCallbackArgs.EventId;
Exception? lastThrownException = null;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.NativeSinks.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.NativeSinks.cs
index d1609f8775e12..9c068cf56d8d7 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.NativeSinks.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.NativeSinks.cs
@@ -138,7 +138,7 @@ public void ContentionStop(double durationNs) =>
ContentionStop(ContentionFlagsMap.Managed, DefaultClrInstanceId, durationNs);
[Event(50, Level = EventLevel.Informational, Message = Messages.WorkerThread, Task = Tasks.ThreadPoolWorkerThread, Opcode = EventOpcode.Start, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void ThreadPoolWorkerThreadStart(
+ public void ThreadPoolWorkerThreadStart(
uint ActiveWorkerThreadCount,
uint RetiredWorkerThreadCount = 0,
ushort ClrInstanceID = DefaultClrInstanceId)
@@ -175,7 +175,7 @@ public void ThreadPoolWorkerThreadWait(
}
[Event(54, Level = EventLevel.Informational, Message = Messages.WorkerThreadAdjustmentSample, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Sample, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void ThreadPoolWorkerThreadAdjustmentSample(
+ public void ThreadPoolWorkerThreadAdjustmentSample(
double Throughput,
ushort ClrInstanceID = DefaultClrInstanceId)
{
@@ -187,7 +187,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentSample(
}
[Event(55, Level = EventLevel.Informational, Message = Messages.WorkerThreadAdjustmentAdjustment, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Adjustment, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void ThreadPoolWorkerThreadAdjustmentAdjustment(
+ public void ThreadPoolWorkerThreadAdjustmentAdjustment(
double AverageThroughput,
uint NewWorkerThreadCount,
ThreadAdjustmentReasonMap Reason,
@@ -201,7 +201,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentAdjustment(
}
[Event(56, Level = EventLevel.Verbose, Message = Messages.WorkerThreadAdjustmentStats, Task = Tasks.ThreadPoolWorkerThreadAdjustment, Opcode = Opcodes.Stats, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void ThreadPoolWorkerThreadAdjustmentStats(
+ public void ThreadPoolWorkerThreadAdjustmentStats(
double Duration,
double Throughput,
double ThreadWave,
@@ -222,7 +222,7 @@ public unsafe void ThreadPoolWorkerThreadAdjustmentStats(
}
[Event(63, Level = EventLevel.Verbose, Message = Messages.IOEnqueue, Task = Tasks.ThreadPool, Opcode = Opcodes.IOEnqueue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)]
- private unsafe void ThreadPoolIOEnqueue(
+ private void ThreadPoolIOEnqueue(
IntPtr NativeOverlapped,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
bool MultiDequeues,
@@ -264,7 +264,7 @@ public void ThreadPoolIOEnqueue(RegisteredWaitHandle registeredWaitHandle)
}
[Event(64, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IODequeue, Version = 0, Keywords = Keywords.ThreadingKeyword | Keywords.ThreadTransferKeyword)]
- private unsafe void ThreadPoolIODequeue(
+ private void ThreadPoolIODequeue(
IntPtr NativeOverlapped,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
ushort ClrInstanceID = DefaultClrInstanceId)
@@ -302,7 +302,7 @@ public void ThreadPoolIODequeue(RegisteredWaitHandle registeredWaitHandle)
}
[Event(60, Level = EventLevel.Verbose, Message = Messages.WorkingThreadCount, Task = Tasks.ThreadPoolWorkingThreadCount, Opcode = EventOpcode.Start, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void ThreadPoolWorkingThreadCount(uint Count, ushort ClrInstanceID = DefaultClrInstanceId)
+ public void ThreadPoolWorkingThreadCount(uint Count, ushort ClrInstanceID = DefaultClrInstanceId)
{
if (!IsEnabled(EventLevel.Verbose, Keywords.ThreadingKeyword))
{
@@ -329,7 +329,7 @@ public unsafe void ThreadPoolIOPack(NativeOverlapped* nativeOverlapped)
}
[Event(65, Level = EventLevel.Verbose, Message = Messages.IO, Task = Tasks.ThreadPool, Opcode = Opcodes.IOPack, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- private unsafe void ThreadPoolIOPack(
+ private void ThreadPoolIOPack(
IntPtr NativeOverlapped,
IntPtr Overlapped, // 0 if the Windows thread pool is used, the relevant info could be obtained from the NativeOverlapped* if necessary
ushort ClrInstanceID = DefaultClrInstanceId)
@@ -339,7 +339,7 @@ private unsafe void ThreadPoolIOPack(
[Event(59, Level = EventLevel.Informational, Message = Messages.MinMaxThreads, Task = Tasks.ThreadPoolMinMaxThreads, Opcode = EventOpcode.Info, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void ThreadPoolMinMaxThreads(
+ public void ThreadPoolMinMaxThreads(
ushort MinWorkerThreads,
ushort MaxWorkerThreads,
ushort MinIOCompletionThreads,
@@ -364,7 +364,7 @@ private void WaitHandleWaitStart(
[NonEvent]
[MethodImpl(MethodImplOptions.NoInlining)]
- public unsafe void WaitHandleWaitStart(
+ public void WaitHandleWaitStart(
WaitHandleWaitSourceMap waitSource = WaitHandleWaitSourceMap.Unknown,
object? associatedObject = null) =>
WaitHandleWaitStart(waitSource, ObjectIDForEvents(associatedObject));
diff --git a/src/libraries/System.Private.CoreLib/src/System/Enum.cs b/src/libraries/System.Private.CoreLib/src/System/Enum.cs
index f559948df33b1..28d95be309436 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Enum.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Enum.cs
@@ -911,7 +911,7 @@ private static bool TryParse(ReadOnlySpan value, bool ignoreCase, b
}
/// Core implementation for all {Try}Parse methods, both generic and non-generic, parsing either by value or by name.
- private static unsafe bool TryParseByValueOrName(
+ private static bool TryParseByValueOrName(
RuntimeType enumType, ReadOnlySpan value, bool ignoreCase, bool throwOnFailure, out TUnderlying result)
where TUnderlying : unmanaged, IBinaryIntegerParseAndFormatInfo
where TStorage : unmanaged, IBinaryIntegerParseAndFormatInfo
@@ -969,7 +969,7 @@ private static unsafe bool TryParseByValueOrName(
return false;
}
- private static unsafe bool TryParseRareTypeByValueOrName(
+ private static bool TryParseRareTypeByValueOrName(
RuntimeType enumType, ReadOnlySpan value, bool ignoreCase, bool throwOnFailure, out TUnderlying result)
where TUnderlying : struct, INumber, IBitwiseOperators, IMinMaxValue
where TStorage : struct, INumber, IBitwiseOperators, IMinMaxValue
diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs
index 9c1e6ddee1d2b..186f0e42c3733 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs
@@ -485,7 +485,7 @@ private static void ThrowCompareOptionsCheckFailed(CompareOptions options)
message: ((options & CompareOptions.Ordinal) != 0) ? SR.Argument_CompareOptionOrdinal : SR.Argument_InvalidFlag);
}
- private unsafe int CompareStringCore(ReadOnlySpan string1, ReadOnlySpan string2, CompareOptions options) =>
+ private int CompareStringCore(ReadOnlySpan string1, ReadOnlySpan string2, CompareOptions options) =>
GlobalizationMode.UseNls ?
NlsCompareString(string1, string2, options) :
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
@@ -863,7 +863,7 @@ public int IndexOf(string source, string value, int startIndex, int count)
return IndexOf(source, value, startIndex, count, CompareOptions.None);
}
- public unsafe int IndexOf(string source, char value, int startIndex, int count, CompareOptions options)
+ public int IndexOf(string source, char value, int startIndex, int count, CompareOptions options)
{
if (source == null)
{
@@ -893,7 +893,7 @@ public unsafe int IndexOf(string source, char value, int startIndex, int count,
return result;
}
- public unsafe int IndexOf(string source, string value, int startIndex, int count, CompareOptions options)
+ public int IndexOf(string source, string value, int startIndex, int count, CompareOptions options)
{
if (source == null)
{
@@ -1579,7 +1579,7 @@ public int GetHashCode(ReadOnlySpan source, CompareOptions options)
}
}
- private unsafe int GetHashCodeOfStringCore(ReadOnlySpan source, CompareOptions options) =>
+ private int GetHashCodeOfStringCore(ReadOnlySpan source, CompareOptions options) =>
GlobalizationMode.UseNls ?
NlsGetHashCodeOfString(source, options) :
IcuGetHashCodeOfString(source, options);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs
index 5b18e8d2b6fcb..68bcde60f941d 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs
@@ -294,7 +294,7 @@ internal static bool EqualsIgnoreCase_Scalar(ref char charA, ref char charB, int
return CompareStringIgnoreCase(ref Unsafe.AddByteOffset(ref charA, byteOffset), length, ref Unsafe.AddByteOffset(ref charB, byteOffset), length) == 0;
}
- internal static unsafe int IndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
+ internal static int IndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
{
if (source == null)
{
@@ -593,7 +593,7 @@ internal static int LastIndexOf(string source, string value, int startIndex, int
return result;
}
- internal static unsafe int LastIndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
+ internal static int LastIndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
{
if (source == null)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs
index 5b6f26637dcac..ef7490d413d49 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs
@@ -515,7 +515,7 @@ public override string ToString()
/// influence which letter or letters of a "word" are uppercased when titlecasing strings. For example
/// "l'arbre" is considered two words in French, whereas "can't" is considered one word in English.
///
- public unsafe string ToTitleCase(string str)
+ public string ToTitleCase(string str)
{
ArgumentNullException.ThrowIfNull(str);
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs
index dc8f28f66fa43..50f649bebbfbc 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs
@@ -60,7 +60,7 @@ public static DirectoryInfo CreateDirectory(string path, UnixFileMode unixCreate
/// An object that represents the directory that was created.
/// contains a directory separator.
/// A new directory cannot be created.
- public static unsafe DirectoryInfo CreateTempSubdirectory(string? prefix = null)
+ public static DirectoryInfo CreateTempSubdirectory(string? prefix = null)
{
EnsureNoDirectorySeparators(prefix);
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Windows.cs
index f65e281eb2ce5..2c0656e106c69 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Windows.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Windows.cs
@@ -22,7 +22,7 @@ internal static void Initialize(
entry.OriginalRootDirectory = originalRootDirectory;
}
- internal unsafe Interop.NtDll.FILE_FULL_DIR_INFORMATION* _info;
+ internal Interop.NtDll.FILE_FULL_DIR_INFORMATION* _info;
/// Gets the full path of the directory this entry resides in.
/// The full path of this entry's directory.
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs
index a4ceade7483f1..5fa91fdd9483e 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs
@@ -78,7 +78,7 @@ private void Init()
///
/// 'true' if new data was found
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe bool GetData()
+ private bool GetData()
{
Debug.Assert(_directoryHandle != (IntPtr)(-1) && _directoryHandle != IntPtr.Zero && !_lastEntryFound);
@@ -121,7 +121,7 @@ private unsafe bool GetData()
}
}
- private unsafe IntPtr CreateRelativeDirectoryHandle(ReadOnlySpan relativePath, string fullPath)
+ private IntPtr CreateRelativeDirectoryHandle(ReadOnlySpan relativePath, string fullPath)
{
(uint status, IntPtr handle) = Interop.NtDll.CreateFile(
relativePath,
@@ -270,7 +270,7 @@ public bool MoveNext()
}
}
- private unsafe void FindNextEntry()
+ private void FindNextEntry()
{
_entry = Interop.NtDll.FILE_FULL_DIR_INFORMATION.GetNextInfo(_entry);
if (_entry != null)
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
index c97d7a9f00626..8c393cfcddb21 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
@@ -154,7 +154,7 @@ public static string GetTempPath()
return path;
}
- private static unsafe delegate* unmanaged GetGetTempPathWFunc()
+ private static delegate* unmanaged GetGetTempPathWFunc()
{
IntPtr kernel32 = Interop.Kernel32.LoadLibraryEx(Interop.Libraries.Kernel32, 0, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32);
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
index 11d7ab331cd33..00ad3543f72c4 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
@@ -700,7 +700,7 @@ private static string CombineInternal(string first, string second, string third,
return JoinInternal(first.AsSpan(), second.AsSpan(), third.AsSpan(), fourth.AsSpan());
}
- private static unsafe string JoinInternal(ReadOnlySpan first, ReadOnlySpan second)
+ private static string JoinInternal(ReadOnlySpan first, ReadOnlySpan second)
{
Debug.Assert(first.Length > 0 && second.Length > 0, "should have dealt with empty paths");
@@ -711,7 +711,7 @@ private static unsafe string JoinInternal(ReadOnlySpan first, ReadOnlySpan
string.Concat(first, PathInternal.DirectorySeparatorCharAsString, second);
}
- private static unsafe string JoinInternal(ReadOnlySpan first, ReadOnlySpan second, ReadOnlySpan third)
+ private static string JoinInternal(ReadOnlySpan first, ReadOnlySpan second, ReadOnlySpan third)
{
Debug.Assert(first.Length > 0 && second.Length > 0 && third.Length > 0, "should have dealt with empty paths");
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/RandomAccess.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/RandomAccess.Windows.cs
index 56a72756f10be..3ece14b5fd82a 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/RandomAccess.Windows.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/RandomAccess.Windows.cs
@@ -765,7 +765,7 @@ private static unsafe IOCompletionCallback AllocateCallback()
{
return new IOCompletionCallback(Callback);
- static unsafe void Callback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
+ static void Callback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
{
CallbackResetEvent state = (CallbackResetEvent)ThreadPoolBoundHandle.GetNativeOverlappedState(pOverlapped)!;
state.ReleaseRefCount(pOverlapped);
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs
index 4e5753655d6b0..7e83e6ca80941 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs
@@ -74,7 +74,7 @@ internal OSFileStreamStrategy(string path, FileMode mode, FileAccess access, Fil
public sealed override bool CanWrite => !_fileHandle.IsClosed && (_access & FileAccess.Write) != 0;
- public sealed override unsafe long Length => _fileHandle.GetFileLength();
+ public sealed override long Length => _fileHandle.GetFileLength();
// in case of concurrent incomplete reads, there can be multiple threads trying to update the position
// at the same time. That is why we are using Interlocked here.
@@ -184,7 +184,7 @@ public sealed override void SetLength(long value)
SetLengthCore(value);
}
- protected unsafe void SetLengthCore(long value)
+ protected void SetLengthCore(long value)
{
Debug.Assert(value >= 0);
diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStreamWrapper.cs b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
index bcbe2b523d58c..284ed64c77a15 100644
--- a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
@@ -87,7 +87,7 @@ public override long Seek(long offset, SeekOrigin loc)
return _unmanagedStream.Seek(offset, loc);
}
- public override unsafe byte[] ToArray()
+ public override byte[] ToArray()
{
byte[] buffer = new byte[_unmanagedStream.Length];
_unmanagedStream.Read(buffer, 0, (int)_unmanagedStream.Length);
@@ -110,7 +110,7 @@ public override void WriteByte(byte value)
}
// Writes this MemoryStream to another stream.
- public override unsafe void WriteTo(Stream stream)
+ public override void WriteTo(Stream stream)
{
ArgumentNullException.ThrowIfNull(stream);
diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
index 174fac083981b..6a2798b537939 100644
--- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
@@ -314,7 +314,7 @@ public static ReadOnlyMemory AsMemory(this string? text, Range range)
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe bool Contains(this Span span, T value) where T : IEquatable? =>
+ public static bool Contains(this Span span, T value) where T : IEquatable? =>
Contains((ReadOnlySpan)span, value);
///
@@ -594,7 +594,7 @@ public static bool ContainsAnyExceptInRange(this ReadOnlySpan span, T lowI
/// The value to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int IndexOf(this Span span, T value) where T : IEquatable? =>
+ public static int IndexOf(this Span span, T value) where T : IEquatable? =>
IndexOf((ReadOnlySpan)span, value);
///
@@ -604,7 +604,7 @@ public static unsafe int IndexOf(this Span span, T value) where T : IEquat
/// The sequence to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int IndexOf(this Span span, ReadOnlySpan value) where T : IEquatable? =>
+ public static int IndexOf(this Span span, ReadOnlySpan value) where T : IEquatable? =>
IndexOf((ReadOnlySpan)span, value);
///
@@ -614,7 +614,7 @@ public static unsafe int IndexOf(this Span span, ReadOnlySpan value) wh
/// The value to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int LastIndexOf(this Span span, T value) where T : IEquatable? =>
+ public static int LastIndexOf(this Span span, T value) where T : IEquatable? =>
LastIndexOf((ReadOnlySpan)span, value);
///
@@ -624,7 +624,7 @@ public static unsafe int LastIndexOf(this Span span, T value) where T : IE
/// The sequence to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int LastIndexOf(this Span span, ReadOnlySpan value) where T : IEquatable? =>
+ public static int LastIndexOf(this Span span, ReadOnlySpan value) where T : IEquatable? =>
LastIndexOf((ReadOnlySpan)span, value);
/// Searches for the first index of any value other than the specified .
@@ -1530,7 +1530,7 @@ private static void ThrowNullLowHighInclusive(T? lowInclusive, T? highInclusi
[Intrinsic] // Unrolled and vectorized for half-constant input
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe bool SequenceEqual(this Span span, ReadOnlySpan other) where T : IEquatable? =>
+ public static bool SequenceEqual(this Span span, ReadOnlySpan other) where T : IEquatable? =>
SequenceEqual((ReadOnlySpan)span, other);
///
@@ -1688,7 +1688,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)),
/// One of the values to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int IndexOfAny(this Span span, T value0, T value1) where T : IEquatable? =>
+ public static int IndexOfAny(this Span span, T value0, T value1) where T : IEquatable? =>
IndexOfAny((ReadOnlySpan)span, value0, value1);
///
@@ -1700,7 +1700,7 @@ public static unsafe int IndexOfAny(this Span span, T value0, T value1) wh
/// One of the values to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int IndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable? =>
+ public static int IndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable? =>
IndexOfAny((ReadOnlySpan)span, value0, value1, value2);
///
@@ -1942,7 +1942,7 @@ public static int IndexOfAny(this ReadOnlySpan span, SearchValues
/// One of the values to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int LastIndexOfAny(this Span span, T value0, T value1) where T : IEquatable? =>
+ public static int LastIndexOfAny(this Span span, T value0, T value1) where T : IEquatable? =>
LastIndexOfAny((ReadOnlySpan)span, value0, value1);
///
@@ -1954,7 +1954,7 @@ public static unsafe int LastIndexOfAny(this Span span, T value0, T value1
/// One of the values to search for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe int LastIndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable? =>
+ public static int LastIndexOfAny(this Span span, T value0, T value1, T value2) where T : IEquatable? =>
LastIndexOfAny((ReadOnlySpan)span, value0, value1, value2);
///
@@ -2251,7 +2251,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(other)),
/// Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T).
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe int SequenceCompareTo(this ReadOnlySpan span, ReadOnlySpan other) where T : IComparable?
+ public static int SequenceCompareTo(this ReadOnlySpan span, ReadOnlySpan other) where T : IComparable?
{
// Can't use IsBitwiseEquatable() below because that only tells us about
// equality checks, not about CompareTo checks.
@@ -2279,7 +2279,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(other)),
[Intrinsic] // Unrolled and vectorized for half-constant input
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[OverloadResolutionPriority(-1)]
- public static unsafe bool StartsWith(this Span span, ReadOnlySpan value) where T : IEquatable? =>
+ public static bool StartsWith(this Span span, ReadOnlySpan value) where T : IEquatable? =>
StartsWith((ReadOnlySpan)span, value);
///
@@ -2308,7 +2308,7 @@ ref Unsafe.As(ref MemoryMarshal.GetReference(value)),
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Intrinsic] // Unrolled and vectorized for half-constant input
[OverloadResolutionPriority(-1)]
- public static unsafe bool EndsWith(this Span span, ReadOnlySpan value) where T : IEquatable? =>
+ public static bool EndsWith(this Span span, ReadOnlySpan value) where T : IEquatable? =>
EndsWith((ReadOnlySpan)span, value);
///
diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.Dragon4.cs b/src/libraries/System.Private.CoreLib/src/System/Number.Dragon4.cs
index 038fdb23947dd..17030547014da 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Number.Dragon4.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Number.Dragon4.cs
@@ -10,7 +10,7 @@ namespace System
// The backing algorithm and the proofs behind it are described in more detail here: https://www.cs.indiana.edu/~dyb/pubs/FP-Printing-PLDI96.pdf
internal static partial class Number
{
- public static unsafe void Dragon4(TNumber value, int cutoffNumber, bool isSignificantDigits, ref NumberBuffer number)
+ public static void Dragon4(TNumber value, int cutoffNumber, bool isSignificantDigits, ref NumberBuffer number)
where TNumber : unmanaged, IBinaryFloatParseAndFormatInfo
{
TNumber v = TNumber.IsNegative(value) ? -value : value;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs
index 55404a6008455..22774a5b3a10c 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs
@@ -598,7 +598,7 @@ public static Matrix4x4 CreateWorld(Vector3 position, Vector3 forward, Vector3 u
/// When this method returns, contains the rotation component of the transformation matrix if the operation succeeded.
/// When the method returns, contains the translation component of the transformation matrix if the operation succeeded.
/// if was decomposed successfully; otherwise, .
- public static unsafe bool Decompose(Matrix4x4 matrix, out Vector3 scale, out Quaternion rotation, out Vector3 translation)
+ public static bool Decompose(Matrix4x4 matrix, out Vector3 scale, out Quaternion rotation, out Vector3 translation)
=> Impl.Decompose(in matrix.AsImpl(), out scale, out rotation, out translation);
/// Tries to invert the specified matrix. The return value indicates whether the operation succeeded.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.Extensions.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.Extensions.cs
index 867e4d15222e6..c85f47cea68b5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.Extensions.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.Extensions.cs
@@ -1,13 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics;
using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
namespace System.Numerics
{
- public static unsafe partial class Vector
+ public static partial class Vector
{
/// Reinterprets a as a new .
/// The plane to reinterpret.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.Extensions.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.Extensions.cs
index b42487e3f6303..e5e402880fb32 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.Extensions.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.Extensions.cs
@@ -1,13 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Diagnostics;
using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
namespace System.Numerics
{
- public static unsafe partial class Vector
+ public static partial class Vector
{
/// Reinterprets a as a new .
/// The quaternion to reinterpret.
diff --git a/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs b/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs
index 37eb86964a266..73c66918ada3d 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ParseNumbers.cs
@@ -14,7 +14,7 @@ internal static class ParseNumbers
internal const int TreatAsI2 = 0x0800;
internal const int IsTight = 0x1000;
- public static unsafe long StringToLong(ReadOnlySpan s, int radix, int flags)
+ public static long StringToLong(ReadOnlySpan s, int radix, int flags)
{
int pos = 0;
return StringToLong(s, radix, flags, ref pos);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Random.CompatImpl.cs b/src/libraries/System.Private.CoreLib/src/System/Random.CompatImpl.cs
index 84282e371f5cc..ace44d4d18c6d 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Random.CompatImpl.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Random.CompatImpl.cs
@@ -193,7 +193,7 @@ public override long NextInt64(long minValue, long maxValue)
}
/// Produces a value in the range [0, ulong.MaxValue].
- private unsafe ulong NextUInt64() =>
+ private ulong NextUInt64() =>
((ulong)(uint)_parent.Next(1 << 22)) |
(((ulong)(uint)_parent.Next(1 << 22)) << 22) |
(((ulong)(uint)_parent.Next(1 << 20)) << 44);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs
index 45853ff96a5a5..05c6ee3213235 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs
@@ -16,7 +16,7 @@ internal static class InvokerEmitUtil
internal delegate object? InvokeFunc_ObjSpanArgs(object? obj, Span