question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AD0001: InvalidOperationException on 2 rules

See original GitHub issue

Description

The rules CollectionShouldContainSingleAnalyzer and CollectionShouldBeEmptyAnalyzer throws InvalidOperationException with message This operation does not apply to an empty instance.

For some weird reason, the stack trace disappear every time I try to expand the issue, this one is the only one which remains:

Severity	Code	Description	Project	File	Line	Category	Suppression State	Tool	Detail Description
Warning	AD0001	Analyzer 'FluentAssertions.Analyzers.CollectionShouldContainSingleAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.	SonarScanner.MSBuild.PreProcessor.Tests		1	Compiler	Active	FluentAssertions.Analyzers	Analyzer 'FluentAssertions.Analyzers.CollectionShouldContainSingleAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: SonarScanner.MSBuild.PreProcessor.Tests
ISymbol: GetActiveRules_UseParamAsKey (Method)
SyntaxTree: C:\Src\SonarSource\scanner-msbuild\tests\SonarScanner.MSBuild.PreProcessor.Tests\SonarWebServiceTest.cs
SyntaxNode: [TestMethod] public void GetActiveRules_UseParamAsKey ... [MethodDeclarationSyntax]@[12810..14357) (264,8)-(305,9)

System.InvalidOperationException: This operation does not apply to an empty instance.
   at System.Collections.Immutable.ImmutableStack`1.Peek()
   at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitElementAccessExpression(ElementAccessExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.ElementAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
   at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
   at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
   at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitInvocationExpression(InvocationExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
   at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
   at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitInvocationExpression(InvocationExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
   at FluentAssertions.Analyzers.FluentAssertionsAnalyzer`1.AnalyzeExpression(ExpressionSyntax expression, SemanticModel semanticModel)
   at FluentAssertions.Analyzers.FluentAssertionsAnalyzer`1.AnalyzeCodeBlock(CodeBlockAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__49`2.<ExecuteBlockActions>b__49_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.

Complete minimal example reproducing the issue

My test project contains quite a lot of tests so it’s quite hard to narrow down to the one failing but I hope that the stacktrace will help you understanding the failure.

Versions

  • Fluent Assertions Analyzers v0.11.4
  • Fluent Assertions v5.5.3
  • Targeting fwk 4.6.1

Additional Information

Seems to be related to #78

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thomaslevesquecommented, Oct 13, 2021

If I’m not mistaken, #100 just swallows exception. So maybe the exception is no longer visible to the user, but it doesn’t mean the underlying problem (whatever it is) is solved.

1reaction
thomaslevesquecommented, Jun 24, 2020

I just hit this as well. This code works fine:

var conditions = blocks[2].Questions[1].Conditions;
conditions.Should().HaveCount(1);

This code triggers the exception:

blocks[2].Questions[1].Conditions.Should().HaveCount(1)
Read more comments on GitHub >

github_iconTop Results From Across the Web

AD0001 With .editorconfig - Developer Community
It seems like when the analyzer is invoked when writing var names, but I'm not sure. > Warning AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.Diagnostics.
Read more >
How to remove warning AD0001 in .Net Core project?
warning AD0001: Analyzer 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' threw an exception of type 'System.
Read more >
c# - What can I do if a code analyzer rule produces an ...
In a sample project, I get the following notification message by the code analzyer: image of the exception. I tried to disable the...
Read more >
An Empirical Study of Software Exceptions in the Field ...
To overcome the challenge of extracting exceptions from query logs, we propose a novel machine learning model for extraction of exception names.
Read more >
Automated exception featurization and search
2 is a flowchart illustrating a computer implemented method of enhancing web-based searching for exception analysis in order to debug ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found