Skip to content
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

VSTHRD002UseJtfRunAnalyzer throws for 'Task.WhenAll(task).Result' #937

Open
ArturDorochowicz opened this issue Oct 8, 2021 · 0 comments

Comments

@ArturDorochowicz
Copy link

Bug description

VSTHRD002UseJtfRunAnalyzer throws for the following code:

var task = Task.Run(async () => {
    await Task.Delay(0).ConfigureAwait(false);
    return 0;
});
_ = Task.WhenAll(task).Result;

The exception is:

CSC : warning AD0001: Analyzer 'Microsoft.VisualStudio.Threading.Analyzers.VSTHRD002UseJtfRunAnalyzer'
threw an exception of type 'System.Exception' with message 'Analyzer failure while processing syntax at [...]:
System.InvalidCastException Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax' 
to type 'Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax'.. Syntax: Task.WhenAll(task).Result'. 

Repro steps

Code to reproduce the behavior.

  1. dotnet new console
  2. dotnet add package Microsoft.VisualStudio.Threading -v 17.0.63
  3. Replace Program.cs with the following and run dotnet build
using System;
using System.Threading.Tasks;

namespace vsthreading
{
    class Program
    {
        static void Main(string[] args)
        {
            var task = Task.Run(async () => {
                await Task.Delay(0).ConfigureAwait(false);
                return 0;
            });
            _ = Task.WhenAll(task).Result;
        }
    }
}

Expected behavior

The analyzer should not throw.

Actual behavior

The analyzer throws an exception.

  • Version used: 17.0.63
  • Application (if applicable): N/A

Additional context

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants