dotnet / dotnet/roslyn-analyzers

CA2008 Do not create tasks without passing a TaskScheduler doesn't appear when pasing method group

Open
#1,908 3 comments 1 reaction 0 assignees View on GitHub
Bug help wanted
Dominant language
No language data
Stars
1.7k
Forks
479
Avg merge
1d 11h
Merged PRs (30d)
3

Description

#### Analyzer package

[Microsoft.CodeAnalysis.FxCopAnalyzers](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers)

#### Package Version

Example: v2.6.2

#### Diagnostic ID

`CA2008: Do not create tasks without passing a TaskScheduler`
> Do not create tasks unless you are using one of the overloads that takes a TaskScheduler. The default is to schedule on TaskScheduler.Current, which would lead to deadlocks. Either use TaskScheduler.Default to schedule on the thread pool, or explicitly pass TaskScheduler.Current to make your intentions clear.

I could not find a documentation page.

#### Repro steps

Use `TaskFactory.StartNew` as method group parameter.

```
public static class Program
{
public static async Task Main(string[] args)
{
var taskFactory = new TaskFactory();
var actions = new Action[] { Console.WriteLine, Console.WriteLine };
await Task.WhenAll(actions.Select(taskFactory.StartNew)).ConfigureAwait(false);
}
}
```

#### Expected behavior

Waring is displayed.

#### Actual behavior

No warning is displayed.

----------

*I just stumpled upon this "behaivor". It's not important for me I just wanted to report it for documentation reasons.*

Contributor guide

Open the contributing guide

Research direction

Reproduce the CA2008 case using TaskFactory.StartNew as a method-group parameter in the supplied example, then locate the analyzer and its existing CA2008 tests. Confirm the current behavior and identify the test or analyzer entry point that handles method-group calls. Done means the supplied pattern produces the expected warning without changing unrelated diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.