-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Description
I'm not sure whether it is considered a bug or part of the new ReadOnlySpan overload/overload resolution breaking change, but it caught me by surprise.
We are currently targeting 8.0(targeting 9.0 it still compiles) but it fails on 10.0 with
"CS4007 Instance of type 'System.ReadOnlySpan' cannot be preserved across 'await' or 'yield' boundary."
(NOTE: in the Visual Studio 2026 editor, there are no red indicators that it is wrong).
Reproduction Steps
This is a simplified example of the actual production code, in the production code GetChecksumAsync is called on 2 different instance.
internal static class Program
{
static async Task Main(string[] args)
{
bool d = !(await GetChecksumAsync())
.SequenceEqual(await GetChecksumAsync());
}
private static async Task<byte[]> GetChecksumAsync()
{
return [];
}
}Expected behavior
I would expect that it remains to compile (and work). i.e. no where in the code am I using ReadOnlySpan and it not being able to transition an await suspense sound like a problem introduced by the compiler/language by going for the ReadOnlySpan overload.
Actual behavior
CS4007 Instance of type 'System.ReadOnlySpan' cannot be preserved across 'await' or 'yield' boundary.
Regression?
Compiles on .NET 8 / 9
Known Workarounds
rewrite the code to dereference the calls into local variables so that there is no await in the argument position.
Configuration
.NET SDK:
Version: 10.0.103
Commit: c2435c3e0f
Workload version: 10.0.103
MSBuild version: 18.0.11+c2435c3e0
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.103\
I didn't try it in other configurations.
Other information
No response