Skip to content

VSTHRD002 code fix throws NRE when compile errors are present #454

@AArnott

Description

@AArnott

Bug description

VSTHRD002 code fix provider throws NRE when activated on a diagnostic with a compile error for one of the arguments.

Repro steps

I had this method, which violated VSTHRD002. Note that there is no using System.Threading; line for this file, so CancellationToken.None did not resolve when I activated the light bulb to look at code fixes.

        public void Serialize<T>(Stream stream, T value, IFormatterResolver resolver = null)
        {
            this.SerializeAsync(stream, value, resolver, CancellationToken.None).GetAwaiter().GetResult();
        }

Expected behavior

The code fix is not offered, or works.

Actual behavior

System.NullReferenceException : Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.Threading.Analyzers.FixUtils.UpdateStatementsForAsyncMethod(BlockSyntax body,SemanticModel semanticModel,Boolean hasResultValue,Boolean returnTypeChanged,CancellationToken cancellationToken)
   at async Microsoft.VisualStudio.Threading.Analyzers.FixUtils.MakeMethodAsync(<Unknown Parameters>)
   at async Microsoft.VisualStudio.Threading.Analyzers.FixUtils.MakeMethodAsync(<Unknown Parameters>)
   at async Microsoft.VisualStudio.Threading.Analyzers.VSTHRD002UseJtfRunCodeFixWithAwait.<>c__DisplayClass3_0.<RegisterCodeFixesAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
  • Version used: 15.8.192

Additional context

This happened while working in the MessagePack-CSharp repo, fix9 branch.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions