Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSC error AD0001 IndexOutOfRangeException #400

Open
starosta33 opened this issue Dec 14, 2024 · 2 comments
Open

CSC error AD0001 IndexOutOfRangeException #400

starosta33 opened this issue Dec 14, 2024 · 2 comments

Comments

@starosta33
Copy link

starosta33 commented Dec 14, 2024

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

@starosta33
Copy link
Author

starosta33 commented Dec 14, 2024

I was able to find the particular assertion for one of the reported issues:

it crashes on this simplification:

ContainsKey("whatever").Should().BeTrue()

where the asserted object is JObject

@starosta33
Copy link
Author

And it crashes here

invocation.TargetMethod.ContainingType.TypeArguments is empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant