diff --git a/src/mscorlib/shared/System/Memory.cs b/src/mscorlib/shared/System/Memory.cs index c220274aef5c..4a1ce4dc9d79 100644 --- a/src/mscorlib/shared/System/Memory.cs +++ b/src/mscorlib/shared/System/Memory.cs @@ -329,6 +329,16 @@ public bool TryGetArray(out ArraySegment arraySegment) return true; } + if (_length == 0) + { +#if FEATURE_PORTABLE_SPAN + arraySegment = new ArraySegment(SpanHelpers.PerTypeValues.EmptyArray); +#else + arraySegment = ArraySegment.Empty; +#endif // FEATURE_PORTABLE_SPAN + return true; + } + arraySegment = default(ArraySegment); return false; } diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.cs b/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.cs index 7fabf1e2fe24..6544081df14c 100644 --- a/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.cs +++ b/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.cs @@ -35,6 +35,16 @@ public static bool TryGetArray(ReadOnlyMemory readOnlyMemory, out ArraySeg return true; } + if (length == 0) + { +#if FEATURE_PORTABLE_SPAN + arraySegment = new ArraySegment(SpanHelpers.PerTypeValues.EmptyArray); +#else + arraySegment = ArraySegment.Empty; +#endif // FEATURE_PORTABLE_SPAN + return true; + } + arraySegment = default; return false; }