diff --git a/Directory.Build.props b/Directory.Build.props
index 61edda987ed..821b777a6d2 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -388,7 +388,7 @@
strict;nullablePublicOnly
true
- $(NoWarn),CS8969
+ $(NoWarn);CS8500;CS8969
portable
true
diff --git a/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs b/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
index d49d1dcb270..608412751f8 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
@@ -58,7 +58,6 @@ namespace System
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ArgIterator_Init2")]
private static partial void Init(ArgIterator* thisPtr, IntPtr cookie, void* ptr);
-#pragma warning disable CS8500 // Takes a pointer to a managed type
// Fetch an argument as a typed referece, advance the iterator.
// Throws an exception if past end of argument list
[CLSCompliant(false)]
diff --git a/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
index 998dcc8340c..9a970480fba 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
@@ -790,9 +790,7 @@ namespace System
// for debug builds we always want to call AllocateNewArray to detect AllocateNewArray bugs
#if !DEBUG
// small arrays are allocated using `new[]` as that is generally faster.
-#pragma warning disable 8500 // sizeof of managed types
if (length < 2048 / sizeof(T))
-#pragma warning restore 8500
{
return new T[length];
}
@@ -892,9 +890,7 @@ namespace System
Configurations = new Dictionary()
};
-#pragma warning disable CS8500 // takes address of managed type
_EnumerateConfigurationValues(&context, &ConfigCallback);
-#pragma warning restore CS8500
return context.Configurations!;
}
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 9bd2298eb93..7bddbfe81ce 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
@@ -93,9 +93,7 @@ namespace System.Reflection
throw new ArgumentException(SR.Arg_TypedReference_Null);
// Passing TypedReference by reference is easier to make correct in native code
-#pragma warning disable CS8500 // Takes a pointer to a managed type
return RuntimeFieldHandle.GetValueDirect(this, (RuntimeType)FieldType, &obj, (RuntimeType?)DeclaringType);
-#pragma warning restore CS8500
}
[DebuggerStepThrough]
@@ -111,9 +109,7 @@ namespace System.Reflection
throw new ArgumentException(SR.Arg_TypedReference_Null);
// Passing TypedReference by reference is easier to make correct in native code
-#pragma warning disable CS8500 // Takes a pointer to a managed type
RuntimeFieldHandle.SetValueDirect(this, (RuntimeType)FieldType, &obj, value, (RuntimeType?)DeclaringType);
-#pragma warning restore CS8500
}
public override RuntimeFieldHandle FieldHandle => new RuntimeFieldHandle(this);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/DependentHandle.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/DependentHandle.cs
index 53819b2cc59..8fb031b15a3 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/DependentHandle.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/DependentHandle.cs
@@ -253,9 +253,7 @@ namespace System.Runtime
// This optimization is the same that is used in GCHandle in RELEASE mode.
// This is not used in DEBUG builds as the runtime performs additional checks.
// The logic below is the inlined copy of ObjectFromHandle in the unmanaged runtime.
-#pragma warning disable 8500 // address of managed types
private static unsafe object? InternalGetTarget(IntPtr dependentHandle) => *(object*)dependentHandle;
-#pragma warning restore 8500
#endif
[MethodImpl(MethodImplOptions.InternalCall)]
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/InternalCalls.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/InternalCalls.cs
index 228f58c0ea4..1dc4d91c396 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/InternalCalls.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/InternalCalls.cs
@@ -23,7 +23,6 @@ namespace System.Runtime.ExceptionServices
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ResumeAtInterceptionLocation")]
internal static unsafe partial void ResumeAtInterceptionLocation(void* pvRegDisplay);
-#pragma warning disable CS8500
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "CallCatchFunclet")]
internal static unsafe partial IntPtr RhpCallCatchFunclet(
ObjectHandleOnStack exceptionObj, byte* pHandlerIP, void* pvRegDisplay, EH.ExInfo* exInfo);
@@ -38,7 +37,6 @@ namespace System.Runtime.ExceptionServices
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "AppendExceptionStackFrame")]
internal static unsafe partial void RhpAppendExceptionStackFrame(ObjectHandleOnStack exceptionObj, IntPtr ip, UIntPtr sp, int flags, EH.ExInfo* exInfo);
-#pragma warning restore CS8500
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "EHEnumInitFromStackFrameIterator")]
[return: MarshalAs(UnmanagedType.Bool)]
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.CoreCLR.cs
index 1238b029598..622cf863cf3 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.CoreCLR.cs
@@ -46,9 +46,7 @@ namespace System.Runtime.InteropServices
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern object? InternalGet(IntPtr handle);
#else
-#pragma warning disable 8500 // address of managed types
internal static unsafe object? InternalGet(IntPtr handle) => *(object*)handle;
-#pragma warning restore 8500
#endif
[MethodImpl(MethodImplOptions.InternalCall)]
diff --git a/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs b/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs
index 6d9c043416f..039b586c01e 100644
--- a/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs
+++ b/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs
@@ -206,7 +206,6 @@ namespace Internal.Runtime.CompilerHelpers
nint blockAddr = MethodTable.SupportsRelativePointers ? (nint)ReadRelPtr32(pBlock) : *pBlock;
if ((blockAddr & GCStaticRegionConstants.Uninitialized) == GCStaticRegionConstants.Uninitialized)
{
-#pragma warning disable CS8500 // takes address of managed type
object? obj = null;
RuntimeImports.RhAllocateNewObject(
new IntPtr(blockAddr & ~GCStaticRegionConstants.Mask),
@@ -234,7 +233,6 @@ namespace Internal.Runtime.CompilerHelpers
// Update the base pointer to point to the pinned object
*pBlock = *(IntPtr*)&obj;
-#pragma warning restore CS8500
}
currentBase++;
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs
index afb4c9a509f..7a242497f30 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs
@@ -15,9 +15,7 @@ namespace System.Runtime
private static unsafe IntPtr RhpCidResolve(IntPtr callerTransitionBlockParam, IntPtr pCell)
{
IntPtr locationOfThisPointer = callerTransitionBlockParam + TransitionBlock.GetThisOffset();
-#pragma warning disable 8500 // address of managed types
object pObject = *(object*)locationOfThisPointer;
-#pragma warning restore 8500
IntPtr dispatchResolveTarget = RhpCidResolve_Worker(pObject, pCell);
return dispatchResolveTarget;
}
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 42401da222e..f74e394df85 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs
@@ -279,12 +279,11 @@ namespace System.Runtime
isFirstFrame = false;
}
#else
-#pragma warning disable CS8500
fixed (EH.ExInfo* pExInfo = &exInfo)
{
InternalCalls.RhpAppendExceptionStackFrame(ObjectHandleOnStack.Create(ref exception), ip, sp, flags, pExInfo);
}
-#pragma warning restore CS8500
+
// Clear flags only if we called the function
isFirstRethrowFrame = false;
isFirstFrame = false;
@@ -686,13 +685,11 @@ namespace System.Runtime
if (unwoundReversePInvoke)
{
object exceptionObj = exInfo.ThrownException;
-#pragma warning disable CS8500
fixed (EH.ExInfo* pExInfo = &exInfo)
{
InternalCalls.RhpCallCatchFunclet(
ObjectHandleOnStack.Create(ref exceptionObj), null, exInfo._frameIter.RegisterSet, pExInfo);
}
-#pragma warning restore CS8500
}
else
{
@@ -922,13 +919,11 @@ namespace System.Runtime
InternalCalls.RhpCallCatchFunclet(
exceptionObj, pCatchHandler, frameIter.RegisterSet, ref exInfo);
#else // NATIVEAOT
-#pragma warning disable CS8500
fixed (EH.ExInfo* pExInfo = &exInfo)
{
InternalCalls.RhpCallCatchFunclet(
ObjectHandleOnStack.Create(ref exceptionObj), pCatchHandler, frameIter.RegisterSet, pExInfo);
}
-#pragma warning restore CS8500
#endif // NATIVEAOT
// currently, RhpCallCatchFunclet will resume after the catch
Debug.Assert(false, "unreachable");
@@ -1209,12 +1204,10 @@ namespace System.Runtime
#if NATIVEAOT
InternalCalls.RhpCallFinallyFunclet(pFinallyHandler, exInfo._frameIter.RegisterSet);
#else // NATIVEAOT
-#pragma warning disable CS8500
fixed (EH.ExInfo* pExInfo = &exInfo)
{
InternalCalls.RhpCallFinallyFunclet(pFinallyHandler, exInfo._frameIter.RegisterSet, pExInfo);
}
-#pragma warning restore CS8500
#endif // NATIVEAOT
exInfo._idxCurClause = MaxTryRegionIdx;
}
diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/GC.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/GC.NativeAot.cs
index 0ee16609157..7f49242cc5f 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/GC.NativeAot.cs
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/GC.NativeAot.cs
@@ -695,9 +695,7 @@ namespace System
Configurations = new Dictionary()
};
-#pragma warning disable CS8500 // takes address of managed type
RuntimeImports.RhEnumerateConfigurationValues(&context, &ConfigCallback);
-#pragma warning restore CS8500
return context.Configurations!;
}
@@ -810,9 +808,7 @@ namespace System
// for debug builds we always want to call AllocateNewArray to detect AllocateNewArray bugs
#if !DEBUG
// small arrays are allocated using `new[]` as that is generally faster.
-#pragma warning disable 8500 // sizeof of managed types
if (length < 2048 / sizeof(T))
-#pragma warning restore 8500
{
return new T[length];
}
@@ -832,9 +828,7 @@ namespace System
throw new OverflowException();
T[]? array = null;
-#pragma warning disable CS8500 // takes address of managed type
RuntimeImports.RhAllocateNewArray(MethodTable.Of(), (uint)length, (uint)flags, &array);
-#pragma warning restore CS8500
if (array == null)
throw new OutOfMemoryException();
@@ -861,9 +855,7 @@ namespace System
throw new OverflowException();
T[]? array = null;
-#pragma warning disable CS8500 // takes address of managed type
RuntimeImports.RhAllocateNewArray(MethodTable.Of(), (uint)length, (uint)flags, &array);
-#pragma warning restore CS8500
if (array == null)
throw new OutOfMemoryException();
diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs
index 6ddac7c3d3d..45bc2f9e199 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/DynamicInvokeInfo.cs
@@ -365,9 +365,7 @@ namespace System.Reflection
else if (argCount == 1)
{
ByReference br = ByReference.Create(ref parameters[0]);
-#pragma warning disable CS8500
void* pByrefStorage = &br;
-#pragma warning restore CS8500
// Since no copy of args is required, pass 'parameters' for both arguments.
CheckArguments(parameters, pByrefStorage, parameters);
@@ -410,9 +408,7 @@ namespace System.Reflection
IntPtr* pStorage = stackalloc IntPtr[2 * argCount];
NativeMemory.Clear(pStorage, (nuint)(2 * argCount) * (nuint)sizeof(IntPtr));
-#pragma warning disable 8500
void* pByRefStorage = (ByReference*)(pStorage + argCount);
-#pragma warning restore 8500
GCFrameRegistration regArgStorage = new((void**)pStorage, (uint)argCount, areByRefs: false);
GCFrameRegistration regByRefStorage = new((void**)pByRefStorage, (uint)argCount, areByRefs: true);
@@ -461,9 +457,7 @@ namespace System.Reflection
IntPtr* pStorage = stackalloc IntPtr[2 * argCount];
NativeMemory.Clear(pStorage, (nuint)(2 * argCount) * (nuint)sizeof(IntPtr));
-#pragma warning disable 8500
void* pByRefStorage = (ByReference*)(pStorage + argCount);
-#pragma warning restore 8500
GCFrameRegistration regArgStorage = new((void**)pStorage, (uint)argCount, areByRefs: false);
GCFrameRegistration regByRefStorage = new((void**)pByRefStorage, (uint)argCount, areByRefs: true);
@@ -501,9 +495,7 @@ namespace System.Reflection
StackAllocatedArguments argStorage = default;
Span