diff --git a/src/libraries/System.Memory/src/Resources/Strings.resx b/src/libraries/System.Memory/src/Resources/Strings.resx
index 6a69c1128e1525..9b144e29550444 100644
--- a/src/libraries/System.Memory/src/Resources/Strings.resx
+++ b/src/libraries/System.Memory/src/Resources/Strings.resx
@@ -123,8 +123,8 @@
GetHashCode() on Span and ReadOnlySpan is not supported.
-
- Cannot use type '{0}'. Only value types without pointers or references are supported.
+
+ The type '{0}' is not supported because it contains references.
Destination is too short.
diff --git a/src/libraries/System.Numerics.Tensors/src/Resources/Strings.resx b/src/libraries/System.Numerics.Tensors/src/Resources/Strings.resx
index 6561dfdafbfa90..e71f7b694759bf 100644
--- a/src/libraries/System.Numerics.Tensors/src/Resources/Strings.resx
+++ b/src/libraries/System.Numerics.Tensors/src/Resources/Strings.resx
@@ -138,8 +138,8 @@
The value '{0}' is not valid for this usage of the type {1}.
-
- Cannot use type '{0}'. Only value types without pointers or references are supported.
+
+ The type '{0}' is not supported because it contains references.
Destination is too short.
diff --git a/src/libraries/System.Numerics.Tensors/src/System/ThrowHelper.cs b/src/libraries/System.Numerics.Tensors/src/System/ThrowHelper.cs
index fdf786f21ce982..199a3aefd2cfb8 100644
--- a/src/libraries/System.Numerics.Tensors/src/System/ThrowHelper.cs
+++ b/src/libraries/System.Numerics.Tensors/src/System/ThrowHelper.cs
@@ -60,9 +60,9 @@ internal static void ThrowArgumentOutOfRangeException()
}
[DoesNotReturn]
- internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType)
+ internal static void ThrowArgument_TypeContainsReferences(Type targetType)
{
- throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType));
+ throw new ArgumentException(SR.Format(SR.Argument_TypeContainsReferences, targetType));
}
[DoesNotReturn]
diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
index 289b1df2b90512..9efedaca5c1461 100644
--- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
+++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
@@ -1375,8 +1375,8 @@
The name of the type is invalid.
-
- Cannot use type '{0}'. Only value types without pointers or references are supported.
+
+ The type '{0}' is not supported because it contains references.
Type '{0}' is not deserializable.
@@ -1456,9 +1456,6 @@
The specified Type must not be a generic type.
-
- The specified Type must be a struct containing no references.
-
Negative field offset is not allowed.
diff --git a/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs b/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs
index a668d3a485e0d4..03efe6f15bb666 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ReadOnlySpan.cs
@@ -103,7 +103,7 @@ public ReadOnlySpan(T[]? array, int start, int length)
public unsafe ReadOnlySpan(void* pointer, int length)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
if (length < 0)
ThrowHelper.ThrowArgumentOutOfRangeException();
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.cs
index 0fc0642c52978b..ae0eb277797f4c 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.cs
@@ -31,7 +31,7 @@ public static unsafe Span AsBytes(Span span)
where T : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
return new Span(
ref Unsafe.As(ref GetReference(span)),
@@ -54,7 +54,7 @@ public static unsafe ReadOnlySpan AsBytes(ReadOnlySpan span)
where T : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
return new ReadOnlySpan(
ref Unsafe.As(ref GetReference(span)),
@@ -116,9 +116,9 @@ public static unsafe Span Cast(Span span)
where TTo : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TFrom));
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TTo));
// Use unsigned integers - unsigned division by constant (especially by power of 2)
// and checked casts are faster and smaller.
@@ -171,9 +171,9 @@ public static unsafe ReadOnlySpan Cast(ReadOnlySpan span
where TTo : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TFrom));
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TTo));
// Use unsigned integers - unsigned division by constant (especially by power of 2)
// and checked casts are faster and smaller.
@@ -470,7 +470,7 @@ public static unsafe T Read(ReadOnlySpan source)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
{
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > source.Length)
{
@@ -489,7 +489,7 @@ public static unsafe bool TryRead(ReadOnlySpan source, out T value)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
{
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)source.Length)
{
@@ -509,7 +509,7 @@ public static unsafe void Write(Span destination, in T value)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
{
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if ((uint)sizeof(T) > (uint)destination.Length)
{
@@ -528,7 +528,7 @@ public static unsafe bool TryWrite(Span destination, in T value)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
{
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)destination.Length)
{
@@ -551,7 +551,7 @@ public static unsafe ref T AsRef(Span span)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
{
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)span.Length)
{
@@ -573,7 +573,7 @@ public static unsafe ref readonly T AsRef(ReadOnlySpan span)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
{
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)span.Length)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs
index acb5c684efd433..93518c386d1bb5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs
@@ -403,7 +403,7 @@ internal static uint AlignedSizeOf() where T : struct
internal static uint SizeOf() where T : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- throw new ArgumentException(SR.Argument_NeedStructWithNoRefs);
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
return (uint)sizeof(T);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Span.cs b/src/libraries/System.Private.CoreLib/src/System/Span.cs
index f1aac7ca423b7b..118c2c6291cafa 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Span.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Span.cs
@@ -108,7 +108,7 @@ public Span(T[]? array, int start, int length)
public unsafe Span(void* pointer, int length)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
+ ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
if (length < 0)
ThrowHelper.ThrowArgumentOutOfRangeException();
diff --git a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs
index 0a73f505159a26..a975b953852885 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs
@@ -78,9 +78,9 @@ internal static void ThrowArrayTypeMismatchException()
}
[DoesNotReturn]
- internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType)
+ internal static void ThrowArgument_TypeContainsReferences(Type targetType)
{
- throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType));
+ throw new ArgumentException(SR.Format(SR.Argument_TypeContainsReferences, targetType));
}
[DoesNotReturn]