dotnet / dotnet/maintenance-packages

System.Memory: C# 14 `new[]` changes cause breaking changes to SequenceEqual

Open
#268 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
44
Forks
24
Avg merge
2d 14h
Merged PRs (30d)
1

Description

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` overload, but *does* have `null` support in the more common overloads.

This issue [*has already been fixed in source*](https://github.com/dotnet/maintenance-packages/pull/236) (thanks @ViveliDuCh), but because no new release has occurred, unexpected breaks can occur when updating `` (typically in multi-targeting projects)

Request: can haz new bits?

Repro example:

``` csproj


Exe

net472;net10.0
enable
enable

14.0




```

with

``` c#
string?[] arr = ["abc", null, "def"];

IList 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, ReadOnlySpan)` version, which fails with a `NullReferenceException`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.