The CancellationToken in a TaskCanceledException on ToListAsync does not match
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
## Why does the `TaskCanceledException` to be the given one but it isn´t
```cs
using (MyDbContext dbContext = new())
{
CancellationTokenSource cts = new();
cts.Cancel();
try
{
await dbContext.People.ToListAsync(cts.Token);
}
catch (TaskCanceledException ex) when (ex.CancellationToken == cts.Token) // that is what I´m expecting
{
Console.WriteLine("No problem");
}
catch (TaskCanceledException ex) when (ex.CancellationToken == CancellationToken.None) // that is what is happening
{
Console.WriteLine("Why?");
}
}
```
Can you explain the given `cts.Token` is not passed to the exception?
### provider and version information
EF Core version: 7.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.5
Contributor guide
Assessment
This issue has not been assessed yet.