Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9154595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:27:10+00:00 2026-06-17T12:27:10+00:00

The problem appears when test case marked with async is failing. App is just

  • 0

The problem appears when test case marked with “async” is failing. App is just crashing in that case, with an unhandled exception of TargetInvocationFail. As far as I understand, the test app is supposed to handle those exceptions, because in case of exception it should just mark respective case as failed. This is exactly what happens with the normal test case (without async / await stuff in it).

I’ve created an issue report for this as well, see http://phone.codeplex.com/workitem/10751. If you have same problem, please upvote the issue. And if you happen to know some workaround, please let me know here.

EDIT: As Stephen Cleary mentioned in the comment, the issue was caused by the fact that my test case procedure was async void, not async Task. I’d reformulate this question as follows then: why changing return type of test case changes the behavior of the exception handling?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:27:11+00:00Added an answer on June 17, 2026 at 12:27 pm

    A good general guideline is “avoid async void“. One reason for this is the difference in exception handling: async Task methods will place any exceptions on their returned Task, which can be observed when that Task is awaited. async void methods will raise their exceptions directly on the SynchronizationContext that was current at the time of the start of the async void method.

    Another thing to keep in mind is that async is primarily a compiler transformation. If you (or anyone else) reflects over an async Task method at runtime, you’ll just see a method with a return type of Task; similarly, an async void method just has a return type of void.

    So, when the test runner sees a method returning void (not knowing that it is an async void method), it executes it and sees it return without (directly) raising an exception, so it marks it as “passed”. Meanwhile, the exception thrown by that async void method is raised directly on the SynchronizationContext (most test runners, including MSTest, provide a thread pool SynchronizationContext), and this exception can cause the test run to report a non-specific error – or it could possibly be ignored if the test run completes quickly enough.

    Modern test runners (including MSTest as of VS2012) understand async Task methods by detecting the return type of Task, and will wait for the Task to complete before considering the test method “finished” and marking it as passed (or failed, if the returned Task contains an exception).

    I have examples of this behavior in MSTest on my blog (including screenshots showing both outputs of the race condition), but note that those blog entries are almost a year old and talk about async unit testing with VS2010. MSTest was updated with VS2012 so that it has reasonable behavior for async Task methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that appears and disappears for mysterious reasons. A while back
semi Resolved It appears that the problem exists only when running in debug mode,
This is a really strange problem, that appears to be somewhat intermittent (although it
Update : The problem appears to have been corrupt DLLs somewhere in my PHP
I'm working on a simple carousel. My problem appears when trying to insert node
I have this mysql tables I want to display with jqgrid. The problem appears
I have a problem where in some cases (appears to be where property type
I've exhausted all efforts at what appears to be a trivial problem, but gotten
I was reading about the subset-sums problem when I came up with what appears
I have a problem with the jQuery UI Slider. The issue also appears on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.