diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs index 1c6cdadaf02279..9aa83a10d6ca4d 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Condition.cs @@ -89,7 +89,9 @@ private unsafe void RemoveWaiter(Waiter waiter) public Condition(Lock @lock) { +#pragma warning disable CS9216 // casting Lock to object ArgumentNullException.ThrowIfNull(@lock); +#pragma warning restore CS9215 _lock = @lock; } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/SyncTable.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/SyncTable.cs index c75a5fe9de40d1..c9ec4990f59075 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/SyncTable.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/SyncTable.cs @@ -140,7 +140,7 @@ public static unsafe int AssignEntry(object obj, int* pHeader) // Found a free entry to assign Debug.Assert(!entry.Owner.IsAllocated); - Debug.Assert(entry.Lock == null); + Debug.Assert(entry.Lock is null); Debug.Assert(entry.HashCode == 0); // Set up the new entry. We should not fail after this point. 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 432540c79ff151..69f873288e7989 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 @@ -5,6 +5,8 @@ using System.Runtime.CompilerServices; using System.Threading; +#pragma warning disable CS9216 // System.Threading.Lock cast to object for object identity + namespace System.Diagnostics.Tracing { // This is part of the NativeRuntimeEventsource, which is the managed version of the Microsoft-Windows-DotNETRuntime provider. diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.cs index 8c85770e1f0aa2..3b9cd5c468349f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.cs @@ -5,6 +5,8 @@ using System.Runtime.CompilerServices; using System.Threading; +#pragma warning disable CS9216 // System.Threading.Lock cast to object for object identity + namespace System.Diagnostics.Tracing { // This is part of the NativeRuntimeEventsource, which is the managed version of the Microsoft-Windows-DotNETRuntime provider. diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs index f9f34ecb19cf04..b7961869eac5d2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs @@ -130,7 +130,7 @@ internal Scope(Lock lockObj, ThreadId currentThreadId) public void Dispose() { Lock? lockObj = _lockObj; - if (lockObj != null) + if (lockObj is not null) { _lockObj = null; lockObj.Exit(_currentThreadId);