diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs index c103bd8fe4304c..90e2ac97a93114 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs @@ -116,7 +116,7 @@ private void AddRange(IEnumerable> enumerable) // back-compat with subclasses that may have overridden the enumerator behavior. if (enumerable.GetType() == typeof(Dictionary)) { - Dictionary source = (Dictionary)enumerable; + Dictionary source = Unsafe.As>(enumerable); if (source.Count == 0) { @@ -161,7 +161,7 @@ private void AddRange(IEnumerable> enumerable) } else if (enumerable.GetType() == typeof(List>)) { - span = CollectionsMarshal.AsSpan((List>)enumerable); + span = CollectionsMarshal.AsSpan(Unsafe.As>>(enumerable)); } else {