You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Analyzer to detect not awaited async calls in a test case #9816
I think a warning should only be produced if a method result is ignored when the method returns an awaitable type. It can be fine to not await the result as long as the user is doing something with it and not ignoring it completely.
I don't think MSTest should do something here specific to testing as it's a general concern and not really specific to testing or MSTest.
In addition, this should already produce a compiler warning CS4014. Did you disable CS4014 in your codebase?
Just to add a data point: there's already a first-party Microsoft analyzer that covers this general case — VSTHRD110 "Observe result of async calls" from Microsoft.VisualStudio.Threading.Analyzers. It fires when an awaitable-returning call's result is ignored completely, which matches the behavior described here (ignoring the result → warn; doing something with it → fine).
On the CS4014 point: CS4014 only fires inside async methods. The repro here is public void AsyncThrow() (non-async), so CS4014 stays silent — that's the actual gap, and it's exactly what VSTHRD110 catches.
That said, I don't think pointing at VSTHRD110 fully closes this: it's not installed in a lot of repos, and MSTest users don't get it out-of-the-box. So there may still be value in an MSTest rule (or extending MSTEST0040) so this is covered by default for test projects, even if the underlying concern is general. Worth deciding whether we want to own that or rely on the external analyzer.
How about have a conditional (e.g. MSTestEnableThreadingAnalyzers property) package reference of Microsoft.VisualStudio.Threading.Analyzers though MSTest meta package to rely on existing code?
Activity
Youssef1313 commentedon Jul 10, 2026
I think a warning should only be produced if a method result is ignored when the method returns an awaitable type. It can be fine to not
awaitthe result as long as the user is doing something with it and not ignoring it completely.I don't think MSTest should do something here specific to testing as it's a general concern and not really specific to testing or MSTest.
In addition, this should already produce a compiler warning CS4014. Did you disable CS4014 in your codebase?
Evangelink commentedon Jul 13, 2026
Just to add a data point: there's already a first-party Microsoft analyzer that covers this general case — VSTHRD110 "Observe result of async calls" from
Microsoft.VisualStudio.Threading.Analyzers. It fires when an awaitable-returning call's result is ignored completely, which matches the behavior described here (ignoring the result → warn; doing something with it → fine).On the CS4014 point: CS4014 only fires inside
asyncmethods. The repro here ispublic void AsyncThrow()(non-async), so CS4014 stays silent — that's the actual gap, and it's exactly what VSTHRD110 catches.That said, I don't think pointing at VSTHRD110 fully closes this: it's not installed in a lot of repos, and MSTest users don't get it out-of-the-box. So there may still be value in an MSTest rule (or extending MSTEST0040) so this is covered by default for test projects, even if the underlying concern is general. Worth deciding whether we want to own that or rely on the external analyzer.
drieseng commentedon Sep 1, 2026
There's another (third-party) analyzer for this:
https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0134.md
stan-sz commentedon Oct 30, 2026
How about have a conditional (e.g.
MSTestEnableThreadingAnalyzersproperty) package reference ofMicrosoft.VisualStudio.Threading.Analyzersthough MSTest meta package to rely on existing code?