Summary
The library projects under Libraries/ are missing .ConfigureAwait(false) on virtually all await calls (~150+ call sites). As library code that may be consumed in contexts with a SynchronizationContext, this is a best practice to prevent unnecessary context capture and potential deadlocks.
Affected projects
| Project |
Approximate await sites |
Microsoft.Teams.Api |
28 |
Microsoft.Teams.Apps |
50+ |
Microsoft.Teams.Common |
9+ |
Microsoft.Teams.AI |
20+ |
Microsoft.Teams.AI.Models.OpenAI |
10+ |
Microsoft.Teams.Plugins.* |
20+ |
Microsoft.Teams.Extensions.* |
5+ |
Why this matters
- Library code should not capture the caller's synchronization context
- Without
ConfigureAwait(false), awaiting a library method from a context with a SynchronizationContext (e.g., ASP.NET on .NET Framework, WPF, WinForms) and then blocking (.Result or .Wait()) causes a deadlock
- Even without deadlocks, unnecessary context switching adds overhead
Suggested fix
Add .ConfigureAwait(false) to every await in library code. This can be enforced with an analyzer like ConfigureAwaitChecker or the built-in CA2007 rule.
Example:
// Before
var res = await _http.SendAsync(req, cancellationToken);
// After
var res = await _http.SendAsync(req, cancellationToken).ConfigureAwait(false);
Summary
The library projects under
Libraries/are missing.ConfigureAwait(false)on virtually allawaitcalls (~150+ call sites). As library code that may be consumed in contexts with aSynchronizationContext, this is a best practice to prevent unnecessary context capture and potential deadlocks.Affected projects
Microsoft.Teams.ApiMicrosoft.Teams.AppsMicrosoft.Teams.CommonMicrosoft.Teams.AIMicrosoft.Teams.AI.Models.OpenAIMicrosoft.Teams.Plugins.*Microsoft.Teams.Extensions.*Why this matters
ConfigureAwait(false), awaiting a library method from a context with aSynchronizationContext(e.g., ASP.NET on .NET Framework, WPF, WinForms) and then blocking (.Resultor.Wait()) causes a deadlockSuggested fix
Add
.ConfigureAwait(false)to everyawaitin library code. This can be enforced with an analyzer like ConfigureAwaitChecker or the built-inCA2007rule.Example: