Repository navigation
Description
Describe the bug
CA2007 reports an await using statement that declares its resource, await using (var declared = resource), but not one whose resource is an expression, await using (resource). Both await resource.DisposeAsync() on the captured context, so both need ConfigureAwait in the same way.
The analyzer only inspects a resource that is a variable declaration. For the expression form, IUsingOperation.Resources is the expression itself, so the analyzer returns without reporting.
Steps to reproduce
Create a class library with dotnet new classlib --name Repro, delete Class1.cs, and add this .editorconfig next to the project file:
root = true
[*.cs]
dotnet_diagnostic.CA2007.severity = warningAdd Sample.cs:
namespace Repro;
public static class Sample
{
public static async Task RunAsync(IAsyncDisposable resource)
{
await using (var declared = resource) { }
await using (resource) { }
await using (resource.ConfigureAwait(false)) { }
}
}Run dotnet build.
Expected behavior
CA2007 reports the first and second statements. The third calls ConfigureAwait(false), so it is not reported.
Actual behavior
CA2007 reports only the first statement:
<repro>/Sample.cs(7,37): warning CA2007: Consider calling ConfigureAwait on the awaited task (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2007)
Is this a regression?
No. CA2007 has checked only the declaration forms since dotnet/roslyn-analyzers#4896 added await using support, and the tests in DoNotDirectlyAwaitATaskTests cover only those forms.
Are there any workarounds?
Write .ConfigureAwait(false) on the resource by hand, as in the third statement. Nothing reports a statement where it is missing.
dotnet --info output
Trimmed to the SDK, runtime environment, and host sections:
.NET SDK:
Version: 11.0.100
Commit: 297acf930f
Workload version: 11.0.100-manifests.08e30c08
MSBuild version: 18.12.2-1.26529.118+297acf930
Runtime Environment:
OS Name: ubuntu
OS Version: 26.10
OS Platform: Linux
RID: linux-x64
Base Path: <dotnet-root>/sdk/11.0.100
Host:
Version: 11.0.0
Architecture: x64
Commit: 297acf930fIDE version
None; reproduced with dotnet build.
Other details
The expression form needs the same type test as the declaration form, applied to the type of the resource expression: report it when the type converts to IAsyncDisposable and is not ConfiguredAsyncDisposable. A code fix for this form appends .ConfigureAwait(false) to the resource expression, which changes the type of no variable, so it does not run into dotnet/roslyn-analyzers#6880.
#57090 is a similar gap in the same rule, for await foreach over WithCancellation(...). dotnet/roslyn-analyzers#7185 asks for await using not to be reported at all; this report asks for the expression form to be reported the same way the declaration form already is.
Drafted by Claude (Anthropic AI assistant).
Activity
github-actions commentedon Dec 6, 2026
🎯 Agentic Issue Triage
Triage Assessment:
@Evangelink| @dotnet/dotnet-analyzershigh- The issue names the CA2007 analyzer, which is directly covered by the matching CODEOWNERS section.Similar issues: #57090 (
potentially related)➡️ Summary: CA2007 does not report
await using (expression)withoutConfigureAwait, though the declaration form is reported. Extend the analyzer to check the resource expression type and add tests.