Skip to content

'Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces.CSharpAddBracesDiagnosticAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'Unexpected true' #33560

@meziantou

Description

@meziantou

Version Used:

VS 2019 preview 3

Warning	AD0001	Analyzer 'Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces.CSharpAddBracesDiagnosticAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'Unexpected true'.	

Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces.CSharpAddBracesDiagnosticAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: SwitchToSource.CLI
SyntaxTree: C:\Users\Documents\Sources\Command.List.cs
SyntaxNode: else System.Console.WriteLine($" ... [ElseClauseSyntax]@[2781..2931) (54,40)-(55,144)

System.InvalidOperationException: Unexpected true
   at Roslyn.Utilities.Contract.ThrowIfTrue(Boolean condition, String message)
   at Microsoft.CodeAnalysis.Shared.Utilities.CommonFormattingHelpers.AppendTextBetween(SyntaxToken token1, SyntaxToken token2, StringBuilder builder)
   at Microsoft.CodeAnalysis.CSharp.Utilities.FormattingRangeHelper.AreTwoTokensOnSameLine(SyntaxToken token1, SyntaxToken token2)
   at Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces.CSharpAddBracesDiagnosticAnalyzer.IsConsideredMultiLine(SyntaxNode statement, SyntaxNode embeddedStatement)
   at Microsoft.CodeAnalysis.CSharp.Diagnostics.AddBraces.CSharpAddBracesDiagnosticAnalyzer.AnalyzeNode(SyntaxNodeAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__50`1.<ExecuteSyntaxNodeAction>b__50_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.

The code around the error (The line comments are not in the original code)

          packageToDisplayList.ForEach(listedPackage => // line 48
          {
              System.Console.WriteLine($"- {listedPackage.PackageId}");
              foreach (var versionInfo in listedPackage.Versions)
              {
                  if (versionInfo.Reason == NonSwitchableReason.None)
                      System.Console.WriteLine($"   * {versionInfo.Version} [{versionInfo.State}]"); // line 54
                  else
                      System.Console.WriteLine($"   * {versionInfo.Version} [{versionInfo.State}: {versionInfo.Reason}]");
              }
          });

Metadata

Metadata

Assignees

Labels

Area-IDEBugDeveloper CommunityThe issue was originally reported on https://developercommunity.visualstudio.comIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringsResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions