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

4

13

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.

Natch answered 24/8, 2021 at 16:42 Comment(2)
I cannot reproduce this using OkNegotiatedContentResult from Microsoft.AspNet.WebApi.Core. Please provide an mcve.Weitzman
@JonasNyrup please see the below answer we used both a 2017 and a 2019 vs and the 2019 one worked and the 2017 one failedNatch
A
5

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.

Alansen answered 26/8, 2021 at 9:38 Comment(2)
Thought this might be the cause we have a old( VS 2015, Server 2012) build server and I was using VS 2019 just needed some ideas / confirmation that it could be. The build server issue has ben raised with my higher ups but yeah looks like to go to Fluent 6.x you have to be using a VS 2019 build which isn't ideal for all. In then end I just reverted back to the 5.x package.Natch
Hmm, Visual Studio 2019 and the SDK (which is what really matters) has been released in April 2019. Visual Studio 2015 is no longer supported by Microsoft. But in reality, you just need the SDKs. For 3 years, I'm not even using Visual Studio anymore and just rely on the SDKs to develop FluentAssertions.Christcross
E
9

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.

Encrata answered 11/2, 2022 at 13:22 Comment(0)
A
5

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.

Alansen answered 26/8, 2021 at 9:38 Comment(2)
Thought this might be the cause we have a old( VS 2015, Server 2012) build server and I was using VS 2019 just needed some ideas / confirmation that it could be. The build server issue has ben raised with my higher ups but yeah looks like to go to Fluent 6.x you have to be using a VS 2019 build which isn't ideal for all. In then end I just reverted back to the 5.x package.Natch
Hmm, Visual Studio 2019 and the SDK (which is what really matters) has been released in April 2019. Visual Studio 2015 is no longer supported by Microsoft. But in reality, you just need the SDKs. For 3 years, I'm not even using Visual Studio anymore and just rely on the SDKs to develop FluentAssertions.Christcross
C
5

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

AssertionExtensions.Should(contentRes).NotBeNull();
Carvelbuilt answered 20/12, 2021 at 9:48 Comment(1)
The only answer that worked for me, without removing <LangVersion>Pythagoreanism
N
2

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

Neman answered 8/10, 2021 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.