Open
Description
Why does the TaskCanceledException
to be the given one but it isn´t
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