exception in errorlist
See original GitHub issueI get several exceptions in the error list: The stack traces seems to be identical for all of them, see below for one of them. A lot of the analyzers mentioned in the stack traces don’t seem to apply for my test method?
I haven’t been able to come up with an example that triggers the bug. Any ideas?
Severity Code Description Project File Line Suppression State Detail Description
Warning AD0001 Analyzer 'FluentAssertions.BestPractices.CollectionShouldEqualOtherCollectionByComparerAnalyzer' threw an exception of type 'System.ArgumentException' with message 'An item with the same key has already been added.'. CIUnitTests 1 Active Analyzer 'FluentAssertions.BestPractices.CollectionShouldEqualOtherCollectionByComparerAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: CIUnitTests
ISymbol: MyTest (Method)
SyntaxTree: C:\Test.cs
SyntaxNode: [TestMethod] public void MyTest ... [MethodDeclarationSyntax]@[8641..10638) (200,8)-(232,9)
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at FluentAssertions.BestPractices.FluentAssertionsWithArgumentsCSharpSyntaxVisitor.VisitArguments(SeparatedSyntaxList`1 arguments)
at FluentAssertions.BestPractices.FluentAssertionsWithArgumentsCSharpSyntaxVisitor.VisitArgumentList(ArgumentListSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax.Accept(CSharpSyntaxVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.BestPractices.FluentAssertionsCSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.BestPractices.FluentAssertionsCSharpSyntaxVisitor.VisitInvocationExpression(InvocationExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.BestPractices.FluentAssertionsCSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.BestPractices.FluentAssertionsCSharpSyntaxVisitor.VisitExpressionStatement(ExpressionStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax.Accept(CSharpSyntaxVisitor visitor)
at FluentAssertions.BestPractices.FluentAssertionsAnalyzer`1.AnalyzeExpressionStatement(ExpressionStatementSyntax statement)
at FluentAssertions.BestPractices.FluentAssertionsAnalyzer`1.AnalyzeCodeBlock(CodeBlockAnalysisContext context)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__48`2.<ExecuteBlockActions>b__48_0(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Built-in Exceptions — Python 3.11.4 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that...
Read more >Am I handling my exceptions in a sensible manner?
Instead of using the separate variable ErrorList , it is better to either generate the user-visible message at the point where you display...
Read more >Control.Exception.ErrorList
0.3: A useful type for collecting error messages. Safe Haskell, None. Language, Haskell2010. Control.Exception.ErrorList.
Read more >Error List Window - Visual Studio
The Error List displays information about a specific error message. You can copy the error number or error string text from the Output...
Read more >Error List stops updating after exception of type ...
Soon after this notice appears, the Error List… stops updating and the error highlights in the code never go away. I tried things...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had a feeling it’s something like this…
Looks like another redesign to the
FluentAssertionsWithArgumentsCSharpSyntaxVisitor
class which extracts the methods into a dictionary containing for each method its arguments.I’m going to add a SanityTests class (not sure about the name yet) that will include cases the should not throw exceptions (and no diagnostics), this will help
As of Fluent Assertions 5.0, I guess you should be able to do so. The API has been changed, so all assertions now start with
Should()
. E.g.ShouldThrow()
andShouldBeEquivalent()
are nowShould().Throw()
andShould().BeEquivalent()
.Most assertions return an
AndConstraint
which is a continutation on the same assertions. Others return anAndWhichConstraint
which allows you to either continue on the same assertion (theAnd
part) or begin an assertion on some result from the assertions. There is alsoWhichValueConstraint
.E.g.
ContainSingle()
return andAndWhich
which lets you assert on that single element.