Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous Call when using Should().NotBeNull() on As item

When I do the following test

var contentRes = res as OkNegotiatedContentResult<List<MachineHealthTableDTO>>;
contentRes.Should().NotBeNull();

I get the error

The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should<TDataRow>(TDataRow)' and 'DataSetAssertionExtensions.Should<TDataSet>(TDataSet)'

This started happening when I upgraded from fluent assertions 5 to 6. Any Idea as to how I can go about resolving this issue would be appreciated.

like image 832
Charlie Hardy Avatar asked Aug 24 '21 16:08

Charlie Hardy


Video Answer


4 Answers

I've just had this exact issue with a .NET Framework 4.8 console app. Would build fine locally but failed the build step in the Azure DevOps pipeline.

Turns out that pipeline was using the vs2017-win2016 vm. Bumping it up to windows-2019 - which used Visual Studio 2019/later version of MSBuild - sorted the issue.

like image 71
rgvlee Avatar answered Oct 16 '22 11:10

rgvlee


The question has already been answered, but I had this same error message and could not understand why FluentAssertions had made so many changes from 4 to 6 version. Turned out, I had multiple versions of the Nuget package installed. So check via "Manage nuget packages" for solution, if you have multiple versions of the Fluent Assertions nuget package installed. See the consolidate tab in Visual Studio.

Consolidate in Manage Packages for Solution

like image 39
Tore Aurstad Avatar answered Oct 16 '22 12:10

Tore Aurstad


I had a very similar issue with an enum

actualEnumValue.Should().Be(expectedEnumValue);

with the error

Error CS0121 The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should(TDataRow)' and 'DataSetAssertionExtensions.Should(TDataSet)'

I finally managed to solve the issue by removing <LangVersion>7</LangVersion> from the project file.

like image 41
SuperRembo Avatar answered Oct 16 '22 13:10

SuperRembo


As a quickfix for the failing build I changed the extension method to

AssertionExtensions.Should(contentRes).NotBeNull();
like image 2
Wojciech Waniek Avatar answered Oct 16 '22 13:10

Wojciech Waniek