-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
This issue has been moved from a ticket on Developer Community.
[severity:It bothers me. A fix would be nice]
Title:
Code Fix "Add await operator" not offered for CS4014 when treated as error - suggests incorrect "var using _" instead
Environment:
Visual Studio Version: 2022 (17.x)
.NET Version: 9.0
Language: C# 12
Operating System: Windows 10
Project Type: Console Application / Class Library
Description:
When CS4014 warning is elevated to ERROR using <WarningsAsErrors>4014</WarningsAsErrors>, Visual Studio's Quick Actions (Ctrl+.) fails to provide the correct "Add await operator" code fix. Instead, it suggests an incorrect and nonsensical "var using _" option.
Steps to Reproduce:
Step 1: Create a new .NET 9 C# Console Application
Step 2: Edit the .csproj file and add:
xml<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<WarningsAsErrors>4014</WarningsAsErrors>
</PropertyGroup>
Step 3: Create the following code:
csharppublic class Program
{
public static void Main()
{
CallAsyncMethod();
}
public static void CallAsyncMethod()
{
SomeAsyncOperation(); // CS4014 ERROR appears here
}
public static async Task SomeAsyncOperation()
{
await Task.Delay(100);
}
}
**Step 4:** Place cursor on the line with CS4014 error and press **Ctrl+.**
---
**Expected Result:**
Quick Actions menu should display:
- Add await operator
- Make method async
- Suppress CS4014
---
**Actual Result:**
Quick Actions menu displays:
- var using _ (INCORRECT - this is not valid C# syntax)
- Suppress CS4014
The "Add await operator" option is completely missing.
Impact:
Critical Workflow Issue:
Prevents using "Fix all in Solution" for bulk async/await corrections
Affects projects with hundreds or thousands of async method calls
Forces manual refactoring of every single async invocation
The suggested "var using _" is syntactically meaningless and misleading
Blocks teams from enforcing async/await best practices via compiler errors
Comparison - When CS4014 is a WARNING (default):
✅ "Add await operator" appears correctly
✅ "Fix all in Solution" works as expected
When CS4014 is an ERROR (via WarningsAsErrors):
❌ "Add await operator" disappears
❌ Incorrect "var using _" suggestion appears
❌ "Fix all in Solution" is unusable
Root Cause:
The code fix provider appears to filter or deprioritize fixes differently when CS4014 is an ERROR versus a WARNING. This breaks the fundamental assumption that elevating a warning to an error should not remove available code fixes.
Minimal Reproduction Project:
File: MinimalRepro.csproj
xml<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<WarningsAsErrors>4014</WarningsAsErrors>
</PropertyGroup>
</Project>
File: Program.cs
csharpclass Program
{
static void Main()
{
DoWork(); // Place cursor here, press Ctrl+.
}
static void DoWork()
{
Task.Delay(100); // CS4014 ERROR - no "Add await" fix offered
}
}
Workaround:
None that scales. Each async call must be manually fixed:
Manually change method signature to async Task
Manually add await keyword
Repeat for every method in the codebase
This defeats the purpose of Roslyn analyzers and Quick Actions.
Requested Fix:
Ensure "Add await operator" code fix is available regardless of CS4014 diagnostic severity
Remove the incorrect "var using _" suggestion
Restore "Fix all in Solution" functionality for CS4014 errors
Add regression tests for code fixes when warnings are treated as errors
Additional Context:
This bug affects the async/await adoption story in .NET. Teams cannot enforce best practices via <WarningsAsErrors> without losing critical IDE productivity features.
The "var using _" suggestion appears to be a confused combination of:
var _ = (discard pattern for fire-and-forget)
await using (IAsyncDisposable pattern)
Neither is appropriate for this scenario.
Original Comments
Feedback Bot on 2/2/2026, 06:37 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Hong Chee (Centific Technologies Inc) [MSFT] on 2/6/2026, 07:24 AM:
Thanks for your sharing the detail steps, I can reproduce this issue through your shared steps on VS Community 2022 (17.14.15) and this issue has been escalated for further investigation, if there is any process, I will inform you immediately.
