Skip to content

TRX per-test file artifact is not emitted as ResultFile on net462 #10312

Closed

Description

Describe the bug

TrxTests.Trx_WhenReportTrxAndResultsDirectoryAreSpecifiedWithArtifact_ArtifactIsCopiedUnderRelativeResultsDirectory fails only for the net462 case. The net8.0 and net10.0 cases of the same [DynamicData] test pass.

The TRX is produced and contains a <UnitTestResult>, but that result has no <ResultFile> element, so the test throws when it tries to read the artifact reference:

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at ...TrxTests.Trx_WhenReportTrxAndResultsDirectoryAreSpecifiedWithArtifact_ArtifactIsCopiedUnderRelativeResultsDirectory(String tfm)
      in test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TrxTests.cs:62

Line 62 is unitTestResult.Descendants(ns + "ResultFile").Single(). The preceding Assert.HasCount(1, trxFiles) and AssertExitCodeIs(ExitCode.Success) both pass, so the failure is specifically that the per-test FileArtifact never becomes a <ResultFile> on .NET Framework.

Since TargetFrameworks.All only includes net462 for the .NET Framework side and only on Windows, this reproduces on Windows agents only.

Version used

main. This is not a regression from recent TRX work — verified by reverting the local TRX streaming-store changes and re-running: the failure is identical, so it reproduces on unmodified main.

Steps To Reproduce

  1. .\build.cmd -pack

  2. Run the single test, e.g.

    dotnet artifacts\bin\Microsoft.Testing.Platform.Acceptance.IntegrationTests\Debug\net11.0\Microsoft.Testing.Platform.Acceptance.IntegrationTests.dll `
      --filter "FullyQualifiedName~Trx_WhenReportTrxAndResultsDirectoryAreSpecifiedWithArtifact_ArtifactIsCopiedUnderRelativeResultsDirectory"
  3. Result: total: 3, failed: 1, succeeded: 2 — the failing case is ("net462").

Reproduced deterministically 4/4 times, so this is a real behavioral difference rather than a flaky test.

Expected behavior

The net462 case behaves like net8.0/net10.0: the per-test artifact is copied under <runDeploymentRoot>/In/<relativeResultsDirectory>/ and referenced from a <ResultFile path="..."> inside the owning <UnitTestResult>.

Actual behavior

The <UnitTestResult> on net462 contains no <ResultFile>, so the artifact reference (and possibly the copy itself) is missing.

Additional context

Starting points for the investigation — two candidate causes, both unverified:

  1. The artifact never reaches the TRX consumer. The test asset (DummyTestFramework in TrxTests.cs) writes test-artifact.txt into Directory.GetCurrentDirectory() and attaches a FileArtifactProperty. On net462 the test host is a native .exe rather than dotnet <dll>, so the process working directory can differ; if the file lands somewhere unexpected, or the property is not carried through the streaming store round-trip on the netstandard2.0 build of the TRX extension, TrxTestResult.FileArtifacts ends up null.
  2. The copy fails and is swallowed as a warning. TrxReportEngine.TryCopyArtifactAndGetHref catches IOException/UnauthorizedAccessException, adds an attachment warning and continues without emitting a <ResultFile> (TrxReportEngine.Results.cs, TrxReportEngine.Artifacts.cs). If that is what happens, the run still exits Success and the only signal is the warning text — which the test does not assert on.

Distinguishing the two is cheap: assert on / dump the test host output for the Unable to copy attachment '...' into the TRX results directory warning, and dump the generated TRX before the Single() call.

Whichever it turns out to be, the fix should also make the failure mode less silent — a dropped per-test attachment currently produces a Success exit code and a warning that no test checks.

Related recent work in this area: #8188 (per-test relative results directory layout) and #8406 (paths in --report-trx-filename).

Activity

  1. added
    needs/triage
    area/trx
    type/test-gap
    on Jul 29, 2026
  2. Evangelink commented on Jul 29, 2026

    @Evangelink
    MemberAuthor

    Update: the defect is not net462-specific — net472 is affected identically.

    While validating #10313, that work ran a full net472 sweep of Microsoft.Testing.Extensions.UnitTests and observed the same two failures that reproduce on net462:

    • TrxReportEngine_GenerateReportAsync_WithArtifactsByTestNode_TrxContainsResultFile
    • TrxReportEngine_GenerateReportAsync_WithArtifactsByTestNodeAndCopyFailure_SkipsBadResultFileAndAddsRunInfo

    That is expected from the root cause — .NET Framework does not transparently promote Windows paths past MAX_PATH to the \\?\ extended-length form, which is a property of the framework rather than of any single version — but it had not been directly observed until now, so recording it.

    Two notes for whoever reviews the fix:

    1. The title of this issue under-describes the scope. The fix on dev/amauryleve/issue-10312-trx-resultfile-net462 correctly says ".NET Framework" in its changelog entry rather than naming a version, which is the accurate framing.
    2. This also explains why the net472 result was initially reported as passing elsewhere: the Arcade test loop aborts after net462 fails, so net472 never ran at all. A green-looking summary in that situation means not executed, not passed — worth checking for a per-TFM log file rather than trusting the absence of a failure.
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/trxtype/test-gap

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions