diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs
index b7dbdb560932d..bf8592946f03e 100644
--- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs
+++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs
@@ -461,9 +461,8 @@ private bool TryAddWithNoTimeValidation(T item, int millisecondsTimeout, Cancell
while (_currentAdders != COMPLETE_ADDING_ON_MASK) spinner.SpinOnce();
throw new InvalidOperationException(SR.BlockingCollection_Completed);
}
-#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn)
+
if (Interlocked.CompareExchange(ref _currentAdders, observedAdders + 1, observedAdders) == observedAdders)
-#pragma warning restore 0420
{
Debug.Assert((observedAdders + 1) <= (~COMPLETE_ADDING_ON_MASK), "The number of concurrent adders thread exceeded the maximum limit.");
break;
@@ -517,9 +516,7 @@ private bool TryAddWithNoTimeValidation(T item, int millisecondsTimeout, Cancell
{
// decrement the adders count
Debug.Assert((_currentAdders & ~COMPLETE_ADDING_ON_MASK) > 0);
-#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn)
Interlocked.Decrement(ref _currentAdders);
-#pragma warning restore 0420
}
}
return waitForSemaphoreWasSuccessful;
@@ -1489,9 +1486,8 @@ public void CompleteAdding()
while (_currentAdders != COMPLETE_ADDING_ON_MASK) spinner.SpinOnce();
return;
}
-#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn)
+
if (Interlocked.CompareExchange(ref _currentAdders, observedAdders | COMPLETE_ADDING_ON_MASK, observedAdders) == observedAdders)
-#pragma warning restore 0420
{
spinner.Reset();
while (_currentAdders != COMPLETE_ADDING_ON_MASK) spinner.SpinOnce();
diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs
index 67d275b0dd192..cd5d92158d0e6 100644
--- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs
+++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs
@@ -273,7 +273,6 @@ public void CopyTo(T[] array, int index)
ToList().CopyTo(array, index);
}
-#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn)
///
/// Inserts an object at the top of the .
///
@@ -662,7 +661,6 @@ private int TryPopCore(int count, out Node poppedHead)
}
}
}
-#pragma warning restore 0420
///
/// Local helper function to copy the popped elements into a given collection
diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs
index 8108e51283268..4c8162a1abdc1 100644
--- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs
+++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs
@@ -630,7 +630,6 @@ IEnumerator IEnumerable.GetEnumerator()
return ((InternalPartitionEnumerable)this).GetEnumerator();
}
-#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn)
///////////////////
//
// Used by GrabChunk_Buffered()
@@ -939,8 +938,11 @@ override protected bool GrabNextChunk(int requestedChunkSize)
{
_localList = new KeyValuePair[_maxChunkSize];
}
+
+#pragma warning disable 0420 // TODO: https://github.com/dotnet/corefx/issues/35022
// make the actual call to the enumerable that grabs a chunk
return _enumerable.GrabChunk(_localList, requestedChunkSize, ref _currentChunkSize.Value);
+#pragma warning restore 0420
}
///
@@ -987,7 +989,6 @@ override public void Dispose()
}
}
#endregion
-#pragma warning restore 0420
}
#endregion
diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs
index 4364836a63bd9..1c37f6f2438d9 100644
--- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs
+++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs
@@ -181,10 +181,7 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
- // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API.
-#pragma warning disable 420
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
-#pragma warning restore 420
{
_catalogs.Dispose();
}
diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs
index 9bdfe79e95a66..d82b2fc2abd1d 100644
--- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs
+++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs
@@ -103,10 +103,7 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
- // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API.
-#pragma warning disable 420
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
-#pragma warning restore 420
{
foreach (ExportProvider provider in _providers)
{
diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs
index e3cf9d858b647..470de40911229 100644
--- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs
+++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs
@@ -87,10 +87,7 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
- // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API.
-#pragma warning disable 420
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
-#pragma warning restore 420
{
INotifyComposablePartCatalogChanged notifyCatalog = _catalog as INotifyComposablePartCatalogChanged;
if (notifyCatalog != null)
diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs
index 3f2b432de9c6e..80ad0aa2b2d6b 100644
--- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs
+++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs
@@ -60,10 +60,7 @@ public virtual IQueryable Parts
{
// Guarantee one time only set _queryableParts
var p = this.AsQueryable();
- // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API.
-#pragma warning disable 420
Interlocked.CompareExchange(ref _queryableParts, p, null);
-#pragma warning restore 420
if (_queryableParts == null)
{
throw new Exception(SR.Diagnostic_InternalExceptionMessage);
diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs
index d7f7817ef0d7c..455a19335562d 100644
--- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs
+++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs
@@ -205,11 +205,7 @@ public object Value
if (_exportedValue == Export._EmptyValue)
{
object exportedValue = GetExportedValueCore();
-
- // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API.
-#pragma warning disable 420
Interlocked.CompareExchange(ref _exportedValue, exportedValue, Export._EmptyValue);
-#pragma warning restore 420
}
return _exportedValue;
diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs
index a00e2477dced5..c6cc44a6e2682 100644
--- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs
+++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs
@@ -35,10 +35,7 @@ protected override void EnsureRunning()
void IDisposable.Dispose()
{
- // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API.
-#pragma warning disable 420
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
-#pragma warning restore 420
{
ReleaseInstanceIfNecessary(CachedInstance);
}
diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs
index 01882e128195f..7b59fb4313122 100644
--- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs
+++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs
@@ -32,13 +32,10 @@ internal bool this[int bit]
if (value) newData = oldData | bit;
else newData = oldData & ~bit;
-#pragma warning disable 0420
int result = Interlocked.CompareExchange(ref _data, newData, oldData);
-#pragma warning restore 0420
-
if (result == oldData) break;
}
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs
index 671829dacb2f5..5b3e6a9d3421a 100644
--- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs
+++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs
@@ -2796,8 +2796,6 @@ private void ReadAsyncCallbackCaptureException(TaskCompletionSource