BADF00D / DisposableFixer

This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.
Other
35 stars 7 forks source link

ArgumentNullException in VS 15.9.4 #103

Open Khaos66 opened 5 years ago

Khaos66 commented 5 years ago

Prerequisites

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>)
BADF00D commented 5 years ago

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.

Khaos66 commented 5 years ago

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)
BADF00D commented 4 years ago

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.

Khaos66 commented 4 years ago

I did not =) Maybe you're right