Skip to content

VSTHRD010 code fix fails inside a lambda #1669

Description

@davkean

Bug description

  • Version of the vssdk-analyzers: 17.11.13-preview
  • Analyzer rule: VSTHRD010
  • Error (exception message, type, and callstack where applicable):

To Reproduce

  1. CTRL+. on the point marked by $
            private JoinableTaskContext joinableTaskContext;
            public int Invoke(IVsInvokablePrivate pInvokable)
            {
                try
                {
                    return this.joinableTaskContext.Factory.Run(async delegate
                    {
                        await this.joinableTaskContext.Factory.SwitchToMainThreadAsync();
                        return pInvokable.$Invoke(); // <--- here
                    });
                }
                catch (Exception ex)
                {
                    return Marshal.GetHRForException(ex);
                }
            }

See: https://github.com/microsoft/vssdktestfx/blob/main/src/Microsoft.VisualStudio.Sdk.TestFramework/GlobalServiceProvider.cs#L299-L313

Expected behavior

No crash

Actual behavior

Crash:

System.ArgumentException : A non-empty value is required.
Parameter name: methodAsString
at Microsoft.VisualStudio.Threading.Analyzers.Utils.FindMethodGroup(SemanticModel semanticModel,String methodAsString)
at async Microsoft.VisualStudio.Threading.Analyzers.VSTHRD010MainThreadUsageCodeFix.RegisterCodeFixesAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeFixes.CodeFixService.GetCodeFixesAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsyncT

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions