DisposableFixer
DisposableFixer copied to clipboard
ArgumentNullException in VS 15.9.4
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>)
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.
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:
- Create a new Winforms project
- (Add new Form1, if not there already)
- Add field: private readonly Timer _timer;
- Add Initialization to constructor: this._timer = new Timer() { Interval = 100 }
- Save Form1.cs
- Switch to the Dispose(bool) method with the methods combobox at the top right
- Add: _timer?.Dispose();
- Save and close Form1.Designer.cs
- Put Cursor on 'new Timer()' and press CTRL+. !BOOM! (sometimes)
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.
I did not =) Maybe you're right