Skip to content

CA2007 does not report await using (expression) without ConfigureAwait #57450

Todo

Description

@glen-84

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 = warning

Add 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:       297acf930f

IDE 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

  1. added
    untriaged
    on Dec 6, 2026
  2. locked and limited conversation to collaborators on Dec 6, 2026
  3. unlocked this conversation on Dec 6, 2026
  4. removed
    untriaged
    on Dec 6, 2026
  5. github-actions commented on Dec 6, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    Similar issues: #57090 (potentially related)

    ➡️ Summary: CA2007 does not report await using (expression) without ConfigureAwait, though the declaration form is reported. Extend the analyzer to check the resource expression type and add tests.

    Generated by 🏷️ Issue Triage for #57450 · copilot · auto (Claude Sonnet 5.5) · ~16 AIC · ⌖ ~2 AIC · ⊞ 15.5K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions