AssertionExtensions.Awaiting Task method is ambiguous with ValueTask
See original GitHub issueWith .net core and c# 8 how are you supposed to use the AssertionExtensions.Awaiting methods? The following code worked before ValueTask was added, but now will give the following compile time error
The call is ambiguous between the following methods or properties: ‘AssertionExtensions.Awaiting<T>(T, Func<T, Task>)’ and ‘AssertionExtensions.Awaiting<T>(T, Func<T, ValueTask>)’
[Test]
public async Task TestFoo()
{
var foo = new Foo();
foo.Awaiting(async f => await f.BarAsync()).Should().NotThrow(); //<--compiler error
}
public class Foo
{
public Task BarAsync() => Task.FromResult(0);
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Testing for exceptions in async methods
Internally this method will run task returned by Func and wait for it. ... //Act and Assert Func<Task> sutMethod = async () =>...
Read more >ValueTask<TResult> Struct (System.Threading.Tasks)
A ValueTask<TResult> instance may only be awaited once, and consumers may not read Result until the instance has completed. If these limitations are ......
Read more >Async block compiler error "Type of expression is ...
I'm trying to make an interactor struct that will call an API method to retrieve a card, but the compiler is throwing "Type...
Read more >Understanding Control Flow with Async and Await in C# | ...
You might recall from the previous guide that the async keyword is actually just a way to eliminate ambiguity for the compiler with...
Read more >Understanding how to use Task and ValueTask - YouTube
[14:42] - What can you do with Task vs ValueTask ? ... C# Async / Await - Make your app more responsive and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Some related information:
I had a similar issue when having to force LangVersion 6 on an old project (to use c# 6), the Should() assertion extensions wouldn’t compile with “The call is ambiguous between the following methods or properties: ‘DataRowAssertionExtensions.Should<TDataRow>(TDataRow)’ and ‘DataSetAssertionExtensions.Should<TDataSet>(TDataSet)’”.
The workaround is changing “using FluentAssertions;” to “using static FluentAssertions.AssertionExtensions;”
The example here still advises async + await: https://fluentassertions.com/exceptions/