Skip to content

CA2025 analyzer still crashes with NRE (AD0001) on 10.0.4xx GA — trigger shape not covered by #53926 #56540

In review

Description

@cratis-direct

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:

  1. Disposables passed into Task.Factory.StartNew as a tuple state object consumed by a static lambda,
  2. a second unawaited Task created in the same scope from those same underlying objects,
  3. a Task.WhenAny race between the two tasks, and
  4. a later foreach disposal of an IDisposable[] 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.WhenAny pair with a dedicated Thread + TaskCompletionSource, which no longer trips the analyzer).
  • dotnet_diagnostic.CA2025.severity = none skips 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

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

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    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.

    Generated by 🏷️ Issue Triage for #56540 · copilot · auto · 23.1 AIC · ⌖ 9.9 AIC · ⊞ 14.4K · ◷

  6. github-actions commented on Oct 8, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.2 AIC · ⌖ 0.661 AIC · ⊞ 12.3K · ◷

  7. github-actions commented on Oct 9, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 13.4 AIC · ⌖ 0.673 AIC · ⊞ 12.3K · ◷

  8. github-actions commented on Oct 10, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 12.8 AIC · ⌖ 0.687 AIC · ⊞ 12.7K · ◷

  9. github-actions commented on Oct 11, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 12.7 AIC · ⌖ 0.754 AIC · ⊞ 13K · ◷

  10. github-actions commented on Oct 12, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 12.9 AIC · ⌖ 0.673 AIC · ⊞ 13K · ◷

  11. github-actions commented on Oct 13, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 13.5 AIC · ⌖ 0.624 AIC · ⊞ 14.4K · ◷

  12. 10 remaining items

  13. github-actions commented on Oct 24, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.5 AIC · ⌖ 0.659 AIC · ⊞ 15K · ◷

  14. github-actions commented on Oct 25, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 13.8 AIC · ⌖ 0.842 AIC · ⊞ 15.2K · ◷

  15. github-actions commented on Oct 27, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14 AIC · ⌖ 0.635 AIC · ⊞ 15.4K · ◷

  16. github-actions commented on Oct 28, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.4 AIC · ⌖ 0.674 AIC · ⊞ 15.4K · ◷

  17. github-actions commented on Oct 29, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.5 AIC · ⌖ 0.826 AIC · ⊞ 15.4K · ◷

  18. github-actions commented on Oct 30, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.5 AIC · ⌖ 0.83 AIC · ⊞ 15.6K · ◷

  19. github-actions commented on Oct 31, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.4 AIC · ⌖ 0.834 AIC · ⊞ 15.6K · ◷

  20. github-actions commented on Nov 1, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.4 AIC · ⌖ 0.767 AIC · ⊞ 15.7K · ◷

  21. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.5 AIC · ⌖ 0.673 AIC · ⊞ 15.7K · ◷

  22. github-actions commented on Nov 3, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.5 AIC · ⌖ 0.843 AIC · ⊞ 15.7K · ◷

  23. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 15.6 AIC · ⌖ 16.1 AIC · ⊞ 15.7K · ◷

  24. github-actions commented on Nov 5, 2026

    @github-actions
    Contributor

    🍪 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! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · 14.8 AIC · ⌖ 16.8 AIC · ⊞ 15.6K · ◷

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions