C# Tools 3.3.0-beta2-19401-05+8ed56b826700926009731ca4d3de0a4e4e652969
I tried running IDE0066 (use 'switch' expression) on a .sln for all of corefx. At some point it failed with the message "'SyntaxEditorBasedFixAllProvider' encountered an error and has been disabled." with the stack:
System.InvalidOperationException : Unexpected value 'BreakStatement' of type 'Microsoft.CodeAnalysis.CSharp.SyntaxKind'
at Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.DefaultVisit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.VisitBreakStatement(BreakStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.BreakStatementSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.RewriteSwitchStatement(SwitchStatementSyntax node,Boolean allowMoveNextStatementToSwitchExpression)
at Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.VisitSwitchStatement(SwitchStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.SwitchStatementSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.GetSwitchExpressionArm(SwitchSectionSyntax node)
at Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.<RewriteSwitchStatement>b__13_1(SwitchSectionSyntax s)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.RewriteSwitchStatement(SwitchStatementSyntax node,Boolean allowMoveNextStatementToSwitchExpression)
at Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.Rewrite(SwitchStatementSyntax switchStatement,SemanticModel semanticModel,SyntaxEditor editor,SyntaxKind nodeToGenerate,Boolean shouldMoveNextStatementToSwitchExpression)
at async Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression.ConvertSwitchStatementToExpressionCodeFixProvider.FixAllAsync(<Unknown Parameters>)
at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(<Unknown Parameters>)
at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.SyntaxEditorBasedFixAllProvider.FixDocumentAsync(<Unknown Parameters>)
at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.SyntaxEditorBasedFixAllProvider.GetFixAsync(<Unknown Parameters>)
at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.SyntaxEditorBasedFixAllProvider.GetFixAsync(<Unknown Parameters>)
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.FixAllGetFixesService.GetFixAllCodeActionAsync(<Unknown Parameters>)
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.FixAllGetFixesService.GetFixAllOperationsAsync(<Unknown Parameters>)
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetOperationsCoreAsync(<Unknown Parameters>)
at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.InvokeWorker(Func`1 getFromDocument,IProgressTracker progressTracker,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.<>c__DisplayClass20_0.<InvokeCore>b__0()
at Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformAction(IExtensionManager extensionManager,Object extension,Action action)
at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
I don't have a simple repro.
tagging @alrz
from the stacktrace, this looks like a nested switch followed by a break which _probably_ belongs to the outer switch. a few regex lookups didn't find any interesting case in corefx so far. I'll see if I can come up with a repro.
@CyrusNajmabadi would it be possible to record the diagnostic location for which the CodeFixProvider throws? so that we can spot the offending code in a fix-all operation.
@mavasani ?
I attached a debugger and found the problematic case. Here's a repro:
```C#
using System;
class Program
{
public static void Main() { }
public DayOfWeek StatusValue() => DayOfWeek.Monday;
public short Value => 0;
public bool ValueBoolean()
{
bool value;
switch (StatusValue())
{
case DayOfWeek.Monday:
switch (Value)
{
case 0:
value = false;
break;
case 1:
value = true;
break;
default:
throw new Exception();
}
break;
default:
throw new Exception();
}
return value;
}
}
```
I have a fix for this and a few others, will open a pr soon.