Problem with async methods
See original GitHub issueIf the class contains async method, the reports are generated incorrectly (opencover, clover, etc)
Example
Async class
using System;
using System.Threading.Tasks;
namespace QnpMiddleService
{
public class AsyncExample
{
public void DoNotAsync()
{
Console.WriteLine("Do Not Async");
}
public async Task DoAsync()
{
await Task.Delay(1);
Console.WriteLine("Do Async");
}
public async Task DoAsyncAnother()
{
await Task.Delay(1);
Console.WriteLine("Do Async another");
}
}
}
opencover report
<?xml-stylesheet type='text/xsl' href='coverage.xsl'?>
<CoverageSession>
<Module hash="353e72eb-ce92-4b3c-ac52-68e0b274e447">
<FullName>QnpMiddleService</FullName>
<ModuleName>QnpMiddleService</ModuleName>
<File uid="1" fullPath="C:\Users\U_M0XZD\Projects\qnp\qnp-middle-service\src\QnpMiddleService\AsyncExample.cs" />
<Class>
<FullName>QnpMiddleService.AsyncExample</FullName>
<Method visited="false" isConstructor="false">
<Name>System.Void QnpMiddleService.AsyncExample::DoNotAsync()</Name>
<FileRef uid="1" />
<SequencePoint vc="0" uspid="1" ordinal="1" sl="10" sc="13" el="10" ec="47" />
</Method>
</Class>
<Class>
<FullName>QnpMiddleService.AsyncExample/<DoAsync>d__1</FullName>
<Method visited="false" isConstructor="false">
<Name>System.Void QnpMiddleService.AsyncExample/<DoAsync>d__1::MoveNext()</Name>
<FileRef uid="1" />
<SequencePoint vc="0" uspid="2" ordinal="1" sl="15" sc="13" el="15" ec="33" />
<SequencePoint vc="0" uspid="3" ordinal="2" sl="15" sc="13" el="15" ec="33" />
<SequencePoint vc="0" uspid="4" ordinal="3" sl="16" sc="13" el="16" ec="43" />
<SequencePoint vc="0" uspid="5" ordinal="4" sl="16" sc="13" el="16" ec="43" />
</Method>
</Class>
<Class>
<FullName>QnpMiddleService.AsyncExample/<DoAsyncAnother>d__2</FullName>
<Method visited="false" isConstructor="false">
<Name>System.Void QnpMiddleService.AsyncExample/<DoAsyncAnother>d__2::MoveNext()</Name>
<FileRef uid="1" />
<SequencePoint vc="0" uspid="6" ordinal="1" sl="21" sc="14" el="21" ec="34" />
<SequencePoint vc="0" uspid="7" ordinal="2" sl="21" sc="14" el="21" ec="34" />
<SequencePoint vc="0" uspid="8" ordinal="3" sl="22" sc="13" el="22" ec="51" />
<SequencePoint vc="0" uspid="9" ordinal="4" sl="22" sc="13" el="22" ec="51" />
</Method>
</Class>
</Module>
</CoverageSession>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
c# - I'm having problems with async
here I get errors: [C:\programming\Stride 3D\MyGame\MyGame\Net.cs(38,13)]: Error: The 'await' operator can only be used within an async method.
Read more >Top 7 Common Async Mistakes - Hamid Mosalla
1- Avoid Using Async Void · 2- Don't Mix Asynchronous Code With Synchronous · 3- Using Synchronous Code in Asynchronous API · 4-...
Read more >Why exceptions in async methods are “dangerous” in C# | ...
If we debug the result, it shows that we have two exceptions, but with no possibility of doing something more accurate in terms...
Read more >C# Async Antipatterns
C# Async Antipatterns · 1. Forgotten await · 2. Ignoring tasks · 3. Using async void methods · 4. Blocking on tasks with...
Read more >Finding Async Method Calls Missing Await - NET Core Tutorials
Due to the way async/await works in C#, your async method may not *always* be awaited. If the async method completes before it...
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
no we should do it during instrumentation and same thing with tests
So, should those 3 methods should be merged and considered the same method? Maybe we can just convert the methodName and methodFullName to the original async method name during instrumentation: https://github.com/lucaslorentz/minicover/blob/master/src/MiniCover/Instrumentation/Instrumenter.cs#L268
Probabbly those generated method names have some pattern that we can rely on.