The span new[] usage in C# 14 can cause overload-resolution changes that have catastrophic breaking changes, as an example when using MemoryExtensions.SequenceEqual on down-level .NET Framework - which (in the released binaries) does not have full support for null values in the ReadOnlySpan<T> overload, but does have null support in the more common overloads.
This issue has already been fixed in source (thanks @ViveliDuCh), but because no new release has occurred, unexpected breaks can occur when updating <LangVersion> (typically in multi-targeting projects)
Request: can haz new bits?
Repro example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- fine on modern .NET; fails on down-level -->
<TargetFrameworks>net472;net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- works with 13 or below, fails with 14 or higher -->
<LangVersion>14.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<!-- latest at time of writing -->
<PackageReference Include="System.Memory" Version="4.6.3" />
</ItemGroup>
</Project>
with
string?[] arr = ["abc", null, "def"];
IList<string?> list = arr;
// this is not impacted, as no overload change
var x = list.SequenceEqual(new[] {"abc", null, "def"});
Console.WriteLine($"List: {x}");
// this new[] here is the bit that makes a difference
var y = arr.SequenceEqual(new[] {"abc", null, "def"});
Console.WriteLine($"Array: {y}");
Specifically: with C# 14 interpreting the new[] via spans, this causes the overload resolution to jump to the (ReadOnlySpan<T>, ReadOnlySpan<T>) version, which fails with a NullReferenceException.
The span
new[]usage in C# 14 can cause overload-resolution changes that have catastrophic breaking changes, as an example when usingMemoryExtensions.SequenceEqualon down-level .NET Framework - which (in the released binaries) does not have full support fornullvalues in theReadOnlySpan<T>overload, but does havenullsupport in the more common overloads.This issue has already been fixed in source (thanks @ViveliDuCh), but because no new release has occurred, unexpected breaks can occur when updating
<LangVersion>(typically in multi-targeting projects)Request: can haz new bits?
Repro example:
with
Specifically: with C# 14 interpreting the
new[]via spans, this causes the overload resolution to jump to the(ReadOnlySpan<T>, ReadOnlySpan<T>)version, which fails with aNullReferenceException.