Repository navigation
Description
Describe the bug
Microsoft.CodeQuality.Analyzers.QualityGuidelines.DoNotPassDisposablesIntoUnawaitedTasksAnalyzer (rule CA2025) throws a NullReferenceException during compilation, surfacing as error AD0001 and failing the build.
This is a different trigger shape than the one in #53926 (local async function called with an instance field + a CancellationTokenSource). The crash reported here needs all of:
- Disposables passed into
Task.Factory.StartNewas a tuple state object consumed by astaticlambda, - a second unawaited
Taskcreated in the same scope from those same underlying objects, - a
Task.WhenAnyrace between the two tasks, and - a later
foreachdisposal of anIDisposable[]holding related streams.
Removing any one of those ingredients makes the crash disappear (verified by minimizing the repro below).
Reproduction
Create a console app (net10.0, <EnableNETAnalyzers>true</EnableNETAnalyzers>, <AnalysisMode>AllEnabledByDefault</AnalysisMode>) with:
using System.IO.Pipelines;
var toServer = new Pipe();
var fromServer = new Pipe();
IDisposable[] streams = [toServer.Writer.AsStream(), fromServer.Reader.AsStream()];
var server = Task.Factory.StartNew(
static state =>
{
var (serverRoot, input, output) = ((string, PipeReader, PipeWriter))state!;
RunServer(serverRoot, input, output);
},
("root", toServer.Reader, fromServer.Writer),
CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
var connecting = ConnectAsync(toServer.Writer.AsStream(), fromServer.Reader.AsStream());
if (await Task.WhenAny(connecting, server) == server)
{
await server;
}
await connecting;
foreach (var stream in streams)
{
stream.Dispose();
}
static async Task<string> ConnectAsync(Stream output, Stream input)
{
await Task.Yield();
return "connected";
}
static void RunServer(string root, PipeReader serverInput, PipeWriter serverOutput)
{
using var input = new StreamReader(serverInput.AsStream());
using var output = new StreamWriter(serverOutput.AsStream()) { AutoFlush = true };
Console.WriteLine(root);
}Build it: the output contains
CSC : error AD0001: Analyzer 'Microsoft.CodeQuality.Analyzers.QualityGuidelines.DoNotPassDisposablesIntoUnawaitedTasksAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Affected versions
All verified locally with the SDK-bundled analyzers (no analyzer PackageReference):
- 10.0.400 — crashes
- 10.0.401 (current latest GA) — crashes
- 11.0.100-rc.1.26425.128 — crashes
#53926 was closed by #55904 ("Prevent CA2025 analyzer crash for direct field arguments", merged 2026-09-16, milestone 12.0-preview1). No .NET 10 GA SDK contains that fix, and this shape may not be covered by it in any case.
Workarounds found
- Restructure the code (we replaced the
Task.Factory.StartNew+Task.WhenAnypair with a dedicatedThread+TaskCompletionSource, which no longer trips the analyzer). dotnet_diagnostic.CA2025.severity = noneskips the analyzer entirely and prevents the crash (verified: the AD0001 disappears with the entry present and returns when it is removed).
Question
Can the crash fix be validated against this shape as well, and serviced into the 10.0.4xx band? We hit this in CI on a self-hosted runner whose SDK tracks the current 10.0 GA, and the only repo-side mitigation that keeps the rule surface otherwise intact is disabling CA2025 outright.
Activity
github-actions commentedon Oct 7, 2026
🎯 Agentic Issue Triage
Triage Assessment:
@Evangelink|@dotnet/dotnet-analyzershigh- The issue names the CA2025 NetAnalyzers analyzer, matching a clear CODEOWNERS section.Similar issues: #53926 (
potentially related)➡️ Summary: CA2025 (DoNotPassDisposablesIntoUnawaitedTasksAnalyzer) throws a NullReferenceException (AD0001) on a tuple-state Task.Factory.StartNew plus Task.WhenAny shape, on 10.0.4xx. Validate the repro against the #55904 fix and consider servicing.
github-actions commentedon Oct 8, 2026
🍪 Issue Monster selected this for Copilot
I have identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 9, 2026
🍪 Issue Monster selected this for Copilot
I have identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 10, 2026
🍪 Issue Monster selected this for Copilot
I have identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 11, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 12, 2026
🍪 Issue Monster selected this for Copilot
I have identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 13, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
10 remaining items
github-actions commentedon Oct 24, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 25, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 27, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 28, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 29, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 30, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Oct 31, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Nov 1, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Nov 2, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Nov 3, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Nov 4, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Nov 5, 2026
🍪 Issue Monster selected this for Copilot
I have identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪