Skip to content

CSC error AD0001 IndexOutOfRangeException #400

Open
@starosta33

Description

@starosta33

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](<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeFixes.CodeFixService.GetCodeFixesAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions