Skip to content

Compilation error caused by exception in an analyzer after updating to v4.8.0 #870

@adrianbanks

Description

@adrianbanks

After updating from v4.7.0 to v4.8.0, we've started getting compilation errors in our solution:

CSC: Error AD0001 : Analyzer 'NUnit.Analyzers.UseSpecificConstraint.UseSpecificConstraintAnalyzer' threw an exception of type 'System.FormatException' with message 'Input string was not in a correct format.'.

There isn't much to go on as the error doesn't link to a line of code, but it appears to be coming from usages of Is.EqualTo("..."). Having turned on detailed logging during the build, this is the error that is happening:

System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.String.System.IConvertible.ToDouble(IFormatProvider provider)
at NUnit.Analyzers.UseSpecificConstraint.UseSpecificConstraintAnalyzer.AnalyzeAssertInvocation(Version nunitVersion, OperationAnalysisContext context, IInvocationOperation assertOperation)
at NUnit.Analyzers.BaseAssertionAnalyzer.AnalyzeInvocation(Version nunitVersion, OperationAnalysisContext context)
at NUnit.Analyzers.BaseAssertionAnalyzer.<>c__DisplayClass5_0.<AnalyzeCompilationStart>b__1(OperationAnalysisContext context)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteOperationAction>b__53_0(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)

This lines up with this line of code in UseSpecificConstraintAnalyzer.

It appears to be that using Assert.That("some string", Is.EqualTo("some other string")) is causing this error by incorrectly attempting to convert the string to a double.

Is there a different assertion format that should be used to check the values of strings now, or is this a bug in the analyzer?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions