DisposableFixer icon indicating copy to clipboard operation
DisposableFixer copied to clipboard

ArgumentNullException in VS 15.9.4

Open Khaos66 opened this issue 6 years ago • 4 comments

Prerequisites

  • [ x] I have written a descriptive issue title
  • [ x] I have verified that I am running the latest version of DisposableFixer: 1.4.0
  • [ x] I have searched open and closed issues to ensure it has not already been reported

Description

I get this exception sometimes with the latest update of Visual Studio 2017.

Although I can't provide the code causing this issue, I hope this call stack will help:

System.ArgumentNullException : Value cannot be null.
Parameter name: syntax
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.CheckSyntaxNode(CSharpSyntaxNode syntax)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfo(ExpressionSyntax expression,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetTypeInfo(SemanticModel semanticModel,ExpressionSyntax expression,CancellationToken cancellationToken)
   at async DisposableFixer.CodeFix.UndisposedMemberCodeFixProvider.CreateDisposeCallInParameterlessDisposeMethod(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<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>)

Khaos66 avatar Jan 08 '19 07:01 Khaos66

It looks like you want to dispose a undisposed field or property. Is there anything special with the type of the member? Is it a field or property? Is the type not yet known (missing reference)? Maybe you can reproduce the issue with dummy code, that can be published here.

BADF00D avatar Jan 08 '19 07:01 BADF00D

I'm trying to reproduce the issue within a sample project. I got it once, but after doing the steps again, I didn't. I'll keep on trying.

These are the building blocks:

  1. Create a new Winforms project
  2. (Add new Form1, if not there already)
  3. Add field: private readonly Timer _timer;
  4. Add Initialization to constructor: this._timer = new Timer() { Interval = 100 }
  5. Save Form1.cs
  6. Switch to the Dispose(bool) method with the methods combobox at the top right
  7. Add: _timer?.Dispose();
  8. Save and close Form1.Designer.cs
  9. Put Cursor on 'new Timer()' and press CTRL+. !BOOM! (sometimes)

Khaos66 avatar Jan 08 '19 15:01 Khaos66

Did you encounter this error once more? Since 8th January I made a lots of bug fixes, maybe this is already fixed. Up to now I was not able to verify this issue. It is kind of strange the the codefix crashes, after you already disposed the field, since the codefix should not have been popped up at all.

BADF00D avatar Oct 26 '19 10:10 BADF00D

I did not =) Maybe you're right

Khaos66 avatar Nov 10 '19 05:11 Khaos66