Repository navigation
Description
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.AzureDevOpsReport2.3.2Microsoft.Testing.Platform2.3.2 (transitive dependency)xunit.v3.mtp-v23.2.2- .NET SDK / target framework: .NET 10
- Agent OS: Azure Pipelines hosted
ubuntu-24.04
Steps To Reproduce
-
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" />
-
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)
-
Run the pipeline.
Expected behavior
- Tests that pass should result in a successful
dotnet testinvocation. --publish-azdo-test-resultsshould 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 code134.
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
Evangelink commentedon Jul 24, 2026
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.
ingenobajon commentedon Jul 28, 2026
Hi Amaury Levé (@Evangelink),
I just tested with
Microsoft.Testing.Extensions.AzureDevOpsReportversion2.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.Evangelink commentedon Jul 28, 2026
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.3never 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 exactObjectDisposedExceptionyou reported on currentmain(which includes #10195), both directly and throughdotnet 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.3run 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
AzureDevOpsReportextension is byte-identical between2.3.2and2.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):
403when the job authorization scope or the Manage test runs permission doesn't allow it.SYSTEM_ACCESSTOKENisn't reaching the process (e.g. theenv: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: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.Evangelink commentedon Jul 28, 2026
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.
ingenobajon commentedon Jul 28, 2026
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_ACCESSTOKENset.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.
Evangelink commentedon Jul 28, 2026
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.
ingenobajon commentedon Jul 29, 2026
I just tested with
Microsoft.Testing.Extensions.AzureDevOpsReportversion2.4.0-preview.26378.13. Before that, I ran the same pipeline with2.3.3to 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
NU1603warnings duringdotnet test:Evangelink commentedon Jul 29, 2026
Thanks for the confirmation! I'll do a new release tomorrow.
For the
NU1603they seem independent from us and probably something linked to your feed.Send the run URL as a session message so dotnet test does not drop it
denisbredikhin commentedon Aug 7, 2026
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?
Evangelink commentedon Aug 24, 2026
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.
Evangelink commentedon Aug 25, 2026
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).