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

NUnit2045 raises IndexOutOfRangeException on CodeAnalysis #420

Closed
ProfBits opened this issue Jan 12, 2022 · 6 comments · Fixed by #421
Closed

NUnit2045 raises IndexOutOfRangeException on CodeAnalysis #420

ProfBits opened this issue Jan 12, 2022 · 6 comments · Fixed by #421
Labels

Comments

@ProfBits
Copy link

Description

NUnit2045 raises IndexOutOfRangeException on executing Analyze -> Run Code Analysis -> On Solution.

Expected: no exception

How to reproduce

  1. Create a new Solution with .net5 ClassLibrary project
  2. Add a NUnitTestProject (.net5)
  3. Update packges of test project
  4. Add NUnit.Analyzers to test project
  5. Execute Analyze -> Run Code Analysis -> On Solution

-> An Waring with the IndexOutOfRangeException caused by NUnit2045 will show up in the ErrorList view

Image:

grafik

Error message:

Severity	Code	Description	Project	File	Line	Suppression State
Warning	AD0001	Analyzer 'NUnit.Analyzers.UseAssertMultiple.UseAssertMultipleAnalyzer' threw an exception of type 'System.IndexOutOfRangeException' with message 'Der Index war außerhalb des Arraybereichs.'.
Exception occurred with following context:
Compilation: TestProject1
IOperation: Invocation
SyntaxTree: C:\Users\shube\source\repos\NUnitAnalyzerBugExample\TestProject1\UnitTest1.cs
SyntaxNode: Assert.Pass() [InvocationExpressionSyntax]@[222..235) (14,12)-(14,25)

System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs.
   bei NUnit.Analyzers.UseAssertMultiple.UseAssertMultipleAnalyzer.AnalyzeAssertInvocation(OperationAnalysisContext context, IInvocationOperation assertOperation)
   bei NUnit.Analyzers.BaseAssertionAnalyzer.AnalyzeInvocation(OperationAnalysisContext context)
   bei Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteOperationAction>b__63_0(ValueTuple`2 data)
   bei Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----

Suppress the following diagnostics to disable this analyzer: NUnit2045	TestProject1		1	Active

Used Version:

  • C# .net5
  • VisualStudio Community 2019 16.11.9
  • NUnit 3.12.2
  • NUnit.Analyzers 3.3.0
  • NUnit.3TestAdapter 4.2.0

I do not have a .net6 or VS 2022 instllation at hand, so can't verify for that.

PS Hope thats enough information

@manfred-brands
Copy link
Member

Thanks for the report.
I haven't managed to reproduce it, but can see when it could happen.

Can you change the Assert.Pass() in your project to something like Assert.Pass("No errors")?
The code assumes at least one argument.

@manfred-brands
Copy link
Member

I managed to reproduce the issue in an nunit test and have a fix.

@ProfBits
Copy link
Author

@manfred-brands Thank you for looking into it so fast, and yes changing it to Assert.Pass("No errors") prevents the error from occuring on my system

@chm-tm
Copy link

chm-tm commented Sep 16, 2022

@manfred-brands We're suffering from this issue. Do you have a release date for 3.4/2.4?

@chm-tm
Copy link

chm-tm commented Sep 16, 2022

@manfred-brands
Copy link
Member

@chm-tm I do not, but I think one is due. I created #478

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

Successfully merging a pull request may close this issue.

4 participants