Skip to content

Microsoft.Testing.Extensions.AzureDevOpsReport crashes during teardown after successful live Azure DevOps test-result publishing #10191

Closed

Description

@ingenobajon

Describe the bug

When running an MTP test project in Azure Pipelines with
Microsoft.Testing.Extensions.AzureDevOpsReport and
--publish-azdo-test-results, all tests complete successfully and the results
are correctly published to and displayed in the Azure DevOps Tests tab.

However, the test process then crashes during teardown with an unhandled
ObjectDisposedException from
AzureDevOpsTestResultsPublisher.Dispose(). This causes the pipeline task to
fail even though there are no failed tests.

Removing only --publish-azdo-test-results prevents the crash, but results are
then not displayed in the Azure DevOps Tests tab.

Version used

  • Microsoft.Testing.Extensions.AzureDevOpsReport 2.3.2
  • Microsoft.Testing.Platform 2.3.2 (transitive dependency)
  • xunit.v3.mtp-v2 3.2.2
  • .NET SDK / target framework: .NET 10
  • Agent OS: Azure Pipelines hosted ubuntu-24.04

Steps To Reproduce

  1. Create an MTP-enabled test project using xUnit v3 and reference:

    <PackageReference Include="Microsoft.Testing.Extensions.AzureDevOpsReport"
                      Version="2.3.2"
                      PrivateAssets="all" />
    <PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" />
  2. Run the project in an Azure Pipelines job with a mapped job access token:

    - task: DotNetCoreCLI@2
      displayName: Run tests
      inputs:
        command: test
        projects: path/to/TestProject.csproj
        publishTestResults: false
        arguments: >-
          --no-build
          --configuration Release
          --
          --report-azdo
          --publish-azdo-test-results
      env:
        SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  3. Run the pipeline.

Expected behavior

  • Tests that pass should result in a successful dotnet test invocation.
  • --publish-azdo-test-results should publish results to the Azure DevOps
    Tests tab without causing the test process or pipeline task to fail.
  • The publisher teardown should be safe if disposal occurs more than once.

Actual behavior

  • The Azure DevOps Tests tab correctly shows the published test results.
  • All tests pass.
  • The test process then fails with an unhandled exception and a non-zero exit
    code. In one observed run, the process exited with code 134.

Example output:

Test run summary: Failed!

  error: 1

  total: 558
  failed: 0
  succeeded: 558
  skipped: 0

Unhandled exception. System.ObjectDisposedException: The CancellationTokenSource has been disposed.
   at System.Threading.CancellationTokenSource.Cancel()
   at Microsoft.Testing.Extensions.AzureDevOpsReport.AzureDevOpsTestResultsPublisher.Dispose()
   at Microsoft.Testing.Platform.Helpers.DisposeHelper.DisposeAsync(Object obj)
   at Microsoft.Testing.Platform.Hosts.CommonHost.DisposeServiceProviderAsync(
       ServiceProvider serviceProvider,
       Func`2 filter,
       List`1 alreadyDisposed,
       Boolean isProcessShutdown)
   at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync()
   at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync()
   at Xunit.MicrosoftTestingPlatform.TestPlatformTestFramework.RunAsync(
       String[] args,
       Action`2 extensionRegistration)

Removing --publish-azdo-test-results while retaining --report-azdo avoids
the process failure, but no test run is shown in the Azure DevOps Tests tab.

Additional context

The failure occurs after the test results have already been published
successfully. This appears to be an idempotency issue in
AzureDevOpsTestResultsPublisher.Dispose(), where Cancel() is called on an
already disposed CancellationTokenSource.

Activity

  1. added theissue type on Jul 24, 2026
  2. added
    needs/triage
    on Jul 24, 2026
  3. added
    area/mtp-extensions
    and removed
    needs/triage
    on Jul 24, 2026
  4. Evangelink commented on Jul 24, 2026

    @Evangelink
    Member

    Hi ingenobajon,

    Thanks for the report! I confirm I found a way to reproduce the error and created a fix that I'll backport to 4.3/2.3.

  5. ingenobajon commented on Jul 28, 2026

    @ingenobajon
    Author

    Hi Amaury Levé (@Evangelink),

    I just tested with Microsoft.Testing.Extensions.AzureDevOpsReport version 2.3.3. The crash is fixed, and the task now completes successfully. However, the test results are no longer published to Azure DevOps, so the Tests tab is missing.

    With version 2.3.2, the task would crash, but the test results were still published and visible in the Azure DevOps UI.

  6. Evangelink commented on Jul 28, 2026

    @Evangelink
    Member

    Hi ingenobajon, thanks a lot for the follow-up — that report was very useful, and it turns out it points at something different from what I originally fixed.

    Two findings after digging in:

    1. 2.3.3 never actually contained a fix for this crash. My change in #10195 fixed a duplicate-disposal bug within a single disposal pass, but the platform runs two disposal passes with separate bookkeeping, so the publisher is still disposed twice. I reproduced the exact ObjectDisposedException you reported on current main (which includes #10195), both directly and through dotnet test. Sorry for the premature "fixed" — that one is on me.

    2. Because of that, the crash disappearing is itself a signal. The crash can only happen once live publishing has actually started (the cancellation token source is only created after the test run is successfully created in Azure DevOps). So a 2.3.3 run that no longer crashes is a run where the test run was never created — which is also exactly why the Tests tab is empty. In other words, the missing crash and the missing results are the same event, not two separate regressions.

    Worth noting: the AzureDevOpsReport extension is byte-identical between 2.3.2 and 2.3.3 (zero files changed), so the upgrade itself can't have changed publishing behaviour. Something about the environment or token changed between those two runs.

    Could you help me confirm which of these two it is? Both produce exactly your symptom (task succeeds, no results, no message):

    • (A) Azure DevOps rejects the run creation — typically 403 when the job authorization scope or the Manage test runs permission doesn't allow it.
    • (B) SYSTEM_ACCESSTOKEN isn't reaching the process (e.g. the env: mapping was dropped, or the step was changed/templated).

    The reason you're seeing nothing is a real bug I'm fixing: every live-publishing failure currently only writes to the diagnostic file log, which is off by default. So the information exists, it's just invisible.

    To get it out of your current run without waiting for a release, add --diagnostic:

    - task: DotNetCoreCLI@2
      displayName: Run tests
      inputs:
        command: test
        projects: path/to/TestProject.csproj
        publishTestResults: false
        arguments: >-
          --no-build
          --configuration Release
          --
          --report-azdo
          --publish-azdo-test-results
          --diagnostic
      env:
        SYSTEM_ACCESSTOKEN: $(System.AccessToken)

    Then search the generated log for Azure DevOps live publishing. You'll get either:

    • ...failed to create the test run. ... status code 403 ... → case (A)
    • ...is disabled because the following environment variables are missing or invalid: SYSTEM_ACCESSTOKEN → case (B)

    I have a PR up that (a) makes Dispose() idempotent so the crash is genuinely fixed, and (b) surfaces these failures on the output device as ##vso[task.logissue type=warning] so this is self-diagnosing instead of silent. I'll link it here shortly.

  7. Evangelink commented on Jul 28, 2026

    @Evangelink
    Member

    PR is up: #10291 — it fixes the crash properly (my #10195 didn't) and makes these failures self-diagnosing so we can tell case (A) from case (B) without waiting on a repro.

  8. ingenobajon commented on Jul 28, 2026

    @ingenobajon
    Author

    Well, you are right, and I apologize. I made a mistake while debugging this. As you pointed out, the task that didn't crash did not have SYSTEM_ACCESSTOKEN set.

    I mistakenly assumed the issue had been fixed after reading the release notes and doing a quick test. Unfortunately, I tested a different task than the one that originally exposed the issue, and I now realize that it was missing the environment variable.

  9. Evangelink commented on Jul 28, 2026

    @Evangelink
    Member

    Thanks for the confirmation! And sorry, the first fix was actually not good.

    If you are able to test "nightly" packages https://github.com/microsoft/testfx/blob/main/docs/preview.md I would appreciate if you could validate the fix so we can work on the next bug-fix release.

  10. ingenobajon commented on Jul 29, 2026

    @ingenobajon
    Author

    I just tested with Microsoft.Testing.Extensions.AzureDevOpsReport version 2.4.0-preview.26378.13. Before that, I ran the same pipeline with 2.3.3 to confirm that the issue was still reproducible.

    The task completes successfully, and the test results are published and displayed in the Azure DevOps UI. It seems that the Tests tab only appears once all tests have finished running, rather than updating live, although I could not confirm this.

    There are still some NU1603 warnings during dotnet test:

    ***.UnitTests.csproj : warning NU1603: xunit.v3.core.mtp-v2 3.2.2 depends on Microsoft.Testing.Extensions.Telemetry (>= 2.0.2) but Microsoft.Testing.Extensions.Telemetry 2.0.2 was not found. Microsoft.Testing.Extensions.Telemetry 2.1.0 was resolved instead.
    ***.UnitTests.csproj : warning NU1603: xunit.v3.core.mtp-v2 3.2.2 depends on Microsoft.Testing.Extensions.TrxReport.Abstractions (>= 2.0.2) but Microsoft.Testing.Extensions.TrxReport.Abstractions 2.0.2 was not found. Microsoft.Testing.Extensions.TrxReport.Abstractions 2.1.0 was resolved instead.
    ***.UnitTests.csproj : warning NU1603: xunit.v3.core.mtp-v2 3.2.2 depends on Microsoft.Testing.Platform (>= 2.0.2) but Microsoft.Testing.Platform 2.0.2 was not found. Microsoft.Testing.Platform 2.1.0 was resolved instead.
    ***.UnitTests.csproj : warning NU1603: xunit.v3.core.mtp-v2 3.2.2 depends on Microsoft.Testing.Platform.MSBuild (>= 2.0.2) but Microsoft.Testing.Platform.MSBuild 2.0.2 was not found. Microsoft.Testing.Platform.MSBuild 2.1.0 was resolved instead.
    
  11. Evangelink commented on Jul 29, 2026

    @Evangelink
    Member

    Thanks for the confirmation! I'll do a new release tomorrow.

    For the NU1603 they seem independent from us and probably something linked to your feed.

  12. denisbredikhin commented on Aug 7, 2026

    @denisbredikhin

    Amaury Levé (@Evangelink) is this issue fixed? Do we need to wait for MSTest 4.4 to get the fix, or is there a way to apply it?

  13. Evangelink commented on Aug 24, 2026

    @Evangelink
    Member

    22. Amaury Levé (@Evangelink) is this issue fixed? Do we need to wait for MSTest 4.4 to get the fix, or is there a way to apply it?

    Sorry for the delay! We had some issues with the release pipeline and I went off on holidays after that. I am just returning and will talk with the team if we want to ship 4.4 this week or ship a bug fix.

  14. Evangelink commented on Aug 25, 2026

    @Evangelink
    Member

    We will make it for 4.4. I'll try to do the release EOW or max early next week (I am waiting for some extra validations and dogfooding).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mtp-extensions

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions