fluentassertions / fluentassertions/fluentassertions.analyzers

CSC error AD0001 IndexOutOfRangeException

Open
#400 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
131
Forks
25
PR merge metrics
No merged PRs in 30d

Description

### Description

I get exceptions both in Visual Studio and from CLI

> CSC error AD0001: Analyzer 'FluentAssertions.Analyzers.FluentAssertionsAnalyzer' threw an exception of type 'System.IndexOutOfRangeException' with message 'Index was outside the bounds of the array.'.

```
System.IndexOutOfRangeException : Index was outside the bounds of the array.
at FluentAssertions.Analyzers.NunitCodeFixProvider.MethodInvocationMatcher.TryGetNext(IOperation operation)
at FluentAssertions.Analyzers.NunitCodeFixProvider.AssertThatMatcher.Matches(INamedTypeSymbol type,IOperationMatcher[] matchers)
at FluentAssertions.Analyzers.NunitCodeFixProvider.AssertThatMatcher.Matches(INamedTypeSymbol type,IOperationMatcher[] matchers,MethodInvocationMatcher methodMatcher,IArgumentOperation& argument)
at FluentAssertions.Analyzers.NunitCodeFixProvider.AssertThatMatcher.Is(String propertyMatcher,MethodInvocationMatcher methodMatcher,IArgumentOperation& argument)
at FluentAssertions.Analyzers.NunitCodeFixProvider.TryComputeFixForNunitThat(IInvocationOperation invocation,CodeFixContext context,NunitCodeFixContext t)
at FluentAssertions.Analyzers.NunitCodeFixProvider.TryComputeFixCore(IInvocationOperation invocation,CodeFixContext context,NunitCodeFixContext t,Diagnostic diagnostic)
at FluentAssertions.Analyzers.TestingFrameworkCodeFixProvider`1.TryComputeFix(IInvocationOperation invocation,CodeFixContext context,TTestContext t,Diagnostic diagnostic)
at async FluentAssertions.Analyzers.CodeFixProviderBase`1.RegisterCodeFixesAsync[TTestContext]()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeFixes.CodeFixService.GetCodeFixesAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T]()
```

### Complete minimal example reproducing the issue

```
Newtonsoft.Json.Linq.JObject actual = new ();
actual.ContainsKey("whatever").Should().BeTrue();
```

### Expected behavior:

no exception thrown during analysis or autofix

### Actual behavior:

crash in VS / failed build

### Versions

* Which version of Fluent Assertions Analyzers are you using?
0.34.1

* Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.0.
.Net 4.6.1, .Net 6.0, .Net 8.0

### Additional Information

The CLI issue goes away when upgrading the FluentAssertions from 6.12.2 to 7.0.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.