Version Used:
VS 17.1
Steps to Reproduce:
-
Install VS 2022 Update 1 Preview 2
-
Create a new .NET Console App
-
Add Below code to swap variables
var rslt1 = 0;
var rslt2= 5;
var tmp = rslt1;
rslt1 = rslt2;
rslt2 = tmp;
-
Place the curser on 'tmp' and press 'Ctrl+." to invoke the context menu
-
Select "Use touples to swap values"
Expected Behavior:
(rslt2, result1) = (rslt1, rslt2);
Actual Behavior:
System.InvalidCastException.

System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.GlobalStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.LocalDeclarationStatementSyntax'.
at Microsoft.CodeAnalysis.CSharp.UseTupleSwap.CSharpUseTupleSwapCodeFixProvider.FixOne(SyntaxEditor editor,Diagnostic diagnostic,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.UseTupleSwap.CSharpUseTupleSwapCodeFixProvider.FixAllAsync(Document document,ImmutableArray`1 diagnostics,SyntaxEditor editor,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.<>c__DisplayClass4_0.b__0(SyntaxEditor editor)
at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.b__0()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsyncT
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
Version Used:
VS 17.1
Steps to Reproduce:
Install VS 2022 Update 1 Preview 2
Create a new .NET Console App
Add Below code to swap variables
Place the curser on 'tmp' and press 'Ctrl+." to invoke the context menu
Select "Use touples to swap values"
Expected Behavior:
(rslt2, result1) = (rslt1, rslt2);
Actual Behavior:
System.InvalidCastException.
System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.GlobalStatementSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.LocalDeclarationStatementSyntax'.
at Microsoft.CodeAnalysis.CSharp.UseTupleSwap.CSharpUseTupleSwapCodeFixProvider.FixOne(SyntaxEditor editor,Diagnostic diagnostic,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.UseTupleSwap.CSharpUseTupleSwapCodeFixProvider.FixAllAsync(Document document,ImmutableArray`1 diagnostics,SyntaxEditor editor,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.<>c__DisplayClass4_0.b__0(SyntaxEditor editor)
at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.b__0()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsyncT
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)