-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5.2 localized Operation cancelled by user
and does not have a specific error code
#2424
Comments
@ionmincu, could you add more info like the underlaying operating system, SqlClient version and if it's an issue starting from a specific SqlClient version, besides providing a simple console app to repro the issue? |
See te attached zip file for repro project. Or inline here: Expand code exampleEfExample.csproj<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="ErikEJ.EntityFramework.SqlServer" Version="6.6.9" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
<!--<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.5" />-->
</ItemGroup>
</Project> Program.csusing System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Globalization;
namespace EfExample
{
internal class Program
{
private const string MyConnectionString = "Server=.\\sqlexpress;Database=SchoolDb;User ID=sa;Password=mypassword;TrustServerCertificate=True";
static async Task Main(string[] args)
{
var context = new SchoolContext(MyConnectionString);
var allCourses = await context.Courses.ToListAsync();
var simulateUseRequestLocalisation = true;
if (simulateUseRequestLocalisation)
{
var culture = new CultureInfo("ja");
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
}
try
{
var cts = new CancellationTokenSource(200);
await context.Database.ExecuteSqlCommandAsync("WAITFOR DELAY '00:00:10';", cts.Token);
//var resuult = await context.Courses.Where(x => x.Students.Any()).ToListAsync(cancel);
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
}
[DbConfigurationType(typeof(System.Data.Entity.SqlServer.MicrosoftSqlDbConfiguration))]
public class SchoolContext : DbContext
{
public SchoolContext(string connectionString) : base(connectionString)
{
Database.SetInitializer(new SchoolDBInitializer());
}
public DbSet<Student> Students { get; set; }
public DbSet<Course> Courses { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
}
public class SchoolDBInitializer : DropCreateDatabaseAlways<SchoolContext>
{
protected override void Seed(SchoolContext context)
{
var students = new List<Student>
{
new Student { LastName = "S", FirstMidName = "Alex", },
new Student { LastName = "M", FirstMidName = "Bob", }
};
var courses = new List<Course>
{
new Course { Title = "Math", Credits = 100 },
new Course { Title = "Astro", Credits = 200 },
};
context.Students.AddRange(students);
context.Courses.AddRange(courses);
context.SaveChanges();
base.Seed(context);
}
}
public class Student
{
[Key]
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
}
public class Course
{
[Key]
public int CourseID { get; set; }
public string Title { get; set; }
public int Credits { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
} Basically in 5.1.5 the message was not localized, and in 5.2.0 it is localized to the request locale. OS:
|
Note the relationship with #26 - at least for async operations, SqlClient should be throwing TaskCanceledException which is the standard way to indicate cancellation. |
I mostly see 5.2 making a breaking change from 5.1.5 (by translating exception messages).
|
We are seeing the same issue while using Aspire (not Aspire specific) when running on Linux (at least WSL) and MacOS (customer reported). dotnet/aspire#1023 (comment) |
@sebastienros and reverting to 5.1.5 "fixes" this? |
@ErikEJ I didn't realize this was specific to a new version and only focused on the "no specific error code", I will try to confirm that, if not I will file another issue. |
Can still repro with 5.1.5, filing a new issue |
@sebastienros Looking forward to your repro details |
@ErikEJ did you check my repo details it should be the same thing for 5.1.5, just replace the version. |
The thrown exception can be improved by including a more specific inner exception, such as cc @David-Engel |
@DavoudEshtehari note that the standard behavior wouldn't be to include TaskCanceledException as an inner exception, but rather to throw a TaskCanceledException (as the top-level exception). This is important as various code reacts differently when a TaskCanceledException is thrown (as opposed to other types). For example, if a Task is terminated because of a TaskCanceledException, its state is Canceled rather than Faulted. So just throwing TaskCanceledException would be the standard behavior here. |
@DavoudEshtehari that issue seems to be very old. I'm talking about an issue that was introduce recently in 5.2. Can we get some kind of disable translations feature for 5.3 ? |
@ionmincu This behavior is identical to .NET Framework, and you've encountered it because of adding support for localization in .NET as well. Unfortunately, there is no easy way to switch it off. |
Is your feature request related to a problem? Please describe.
In MDS 5.2 when
Operation canceled by user
occurs there is no way to tell from the exception that the operation was canceled.We can't just look at the token, the application is huge, and we are using ApplicationInsights to track exceptions using
ITelemetryProcessor
to add custom dimentions on which exceptions to ignore.Now because the exception message is Localized we can't reliably tell if the operation was from a canceled token.
For example when the Current culture to
ja
.Describe the solution you'd like
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
How to repro
See te attached zip file for repro project. Or inline here:
Expand code example
EfExample.csproj
Program.cs
Additional context
ErikEJ.EntityFramework.SqlServer
Stacktrace.
The text was updated successfully, but these errors were encountered: