-
Notifications
You must be signed in to change notification settings - Fork 463
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
CA2016: Forward cancellation token codefix is incorrect #4842
Comments
We may want to change the analyzer behavior to only fire in situations where we are calling a method with a cancellation token as an optional parameter with a special list of known framework apis where the two method signatures are considered semantically equivalent. |
I believe the analyzer here is correct. The code fix should be updated to account for the case where the original parameter list is:
and the new parameter list is:
|
I see, we just want to make sure that the codefix does the right thing. I mis-read the issue |
While this is interesting case to test and make sure it's working, the case meant for EF Core is different. The old signature is
and the new is:
|
this not working got me error say: |
I think the extra I'll take a look. Update: The cancellationToken parameter can only be in the last position: See: Lines 211 to 227 in a0522af
but we need to consider the |
@carlossanlop Well, it's going to make a mistake to me. so if have a params object, should CancellationToken put in the first parameter of method what's wrong? |
So looking into this more deeply, I don't think this is an issue with CA2016. This is an issue with allowing value types to get automatically boxed because of the I cannot seem to repro the case where you are getting an error. Can you please share a code snippet? This code works fine and shows no errors: using System;
using System.Threading;
using System.Threading.Tasks;
namespace N
{
class C
{
static async Task MyAsync(string id, CancellationToken ct)
{
await MethodAsync(CancellationToken.None, id); // This is using the second overload correctly (which takes a ct as first parameter)
await MethodAsync(id, CancellationToken.None); // This is not showing any errors because we are boxing the struct, causing the first overload to be used
await MethodAsync(o: id, ct: ct); // This is using the second overload correctly (named parameters force using ct as the first parameter)
}
static Task<int> MethodAsync(params object[] o) { Console.WriteLine(o); return Task.FromResult(1); }
static Task<int> MethodAsync(CancellationToken ct, params object[] o) { Console.WriteLine($"{ct} {o}"); return Task.FromResult(2); }
}
} @mavasani what can we do about this, since it's unrelated to CA2016? |
@carlossanlop Thanks for feedback well I do passing 2 parameter to params object[] with CancellationToken got me error say :entity type UserRole is defined with a 2 key property, but 3 values were passed to the DbSet.Find method |
@arminatwork User.FindAsync(new object[] { userId, roleId}, cancellationToken); What is the definition of |
@jmarolf in this issues is my problem FindAsync rough edges when passing CancellationToken |
@arminatwork @jmarolf Are we good to close this issue? |
Well no |
I'll update the bug with a description of the issue so its clear what the issue is. |
updated with a repo @arianmotamedi is my description of the problem correct? |
I think you tagged the wrong person :) |
:( woops @arminatwork is my description of the problem correct? |
Ok👍 |
What do you mean? |
well I am updating a bug on others behalf I wanted to make sure the expected/actual was correct just to be safe. |
@jmarolf |
the snark :) |
See dotnet/efcore#22667
cc: @carlossanlop
given a type that contains overloads like this:
and is called like this:
Actual
today CA2016 suggests this as a codefix:
Expected
if items at the previous call site was part of a
params
array then the codefix should wrap those elements inside anew object[]
expressionan alternative could be
The text was updated successfully, but these errors were encountered: