diff --git a/src/Common/src/CoreLib/System/ReadOnlySpan.cs b/src/Common/src/CoreLib/System/ReadOnlySpan.cs index 28fb2e33e052..7a8243d669a0 100644 --- a/src/Common/src/CoreLib/System/ReadOnlySpan.cs +++ b/src/Common/src/CoreLib/System/ReadOnlySpan.cs @@ -261,12 +261,13 @@ public override int GetHashCode() /// /// Defines an implicit conversion of an array to a /// - public static implicit operator ReadOnlySpan(T[] array) => new ReadOnlySpan(array); + public static implicit operator ReadOnlySpan(T[] array) => array != null ? new ReadOnlySpan(array) : default; /// /// Defines an implicit conversion of a to a /// - public static implicit operator ReadOnlySpan(ArraySegment arraySegment) => new ReadOnlySpan(arraySegment.Array, arraySegment.Offset, arraySegment.Count); + public static implicit operator ReadOnlySpan(ArraySegment arraySegment) + => arraySegment.Array != null ? new ReadOnlySpan(arraySegment.Array, arraySegment.Offset, arraySegment.Count) : default; /// /// Forms a slice out of the given read-only span, beginning at 'start'. diff --git a/src/Common/src/CoreLib/System/Span.cs b/src/Common/src/CoreLib/System/Span.cs index 90ef2fca068f..ca146aef6597 100644 --- a/src/Common/src/CoreLib/System/Span.cs +++ b/src/Common/src/CoreLib/System/Span.cs @@ -342,12 +342,13 @@ public override int GetHashCode() /// /// Defines an implicit conversion of an array to a /// - public static implicit operator Span(T[] array) => new Span(array); + public static implicit operator Span(T[] array) => array != null ? new Span(array) : default; /// /// Defines an implicit conversion of a to a /// - public static implicit operator Span(ArraySegment arraySegment) => new Span(arraySegment.Array, arraySegment.Offset, arraySegment.Count); + public static implicit operator Span(ArraySegment arraySegment) + => arraySegment.Array != null ? new Span(arraySegment.Array, arraySegment.Offset, arraySegment.Count) : default; /// /// Defines an implicit conversion of a to a