question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with async methods

See original GitHub issue

If 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/&lt;DoAsync&gt;d__1</FullName>
      <Method visited="false" isConstructor="false">
        <Name>System.Void QnpMiddleService.AsyncExample/&lt;DoAsync&gt;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/&lt;DoAsyncAnother&gt;d__2</FullName>
      <Method visited="false" isConstructor="false">
        <Name>System.Void QnpMiddleService.AsyncExample/&lt;DoAsyncAnother&gt;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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bhugotcommented, Mar 20, 2018

no we should do it during instrumentation and same thing with tests

1reaction
lucaslorentzcommented, Mar 18, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found