Repository navigation
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
-
.\build.cmd -pack -
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"
-
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:
- The artifact never reaches the TRX consumer. The test asset (
DummyTestFrameworkinTrxTests.cs) writestest-artifact.txtintoDirectory.GetCurrentDirectory()and attaches aFileArtifactProperty. Onnet462the test host is a native.exerather thandotnet <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.FileArtifactsends up null. - The copy fails and is swallowed as a warning.
TrxReportEngine.TryCopyArtifactAndGetHrefcatchesIOException/UnauthorizedAccessException, adds an attachment warning andcontinues without emitting a<ResultFile>(TrxReportEngine.Results.cs,TrxReportEngine.Artifacts.cs). If that is what happens, the run still exitsSuccessand 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
Evangelink commentedon Jul 29, 2026
Update: the defect is not net462-specific — net472 is affected identically.
While validating #10313, that work ran a full
net472sweep ofMicrosoft.Testing.Extensions.UnitTestsand observed the same two failures that reproduce onnet462:TrxReportEngine_GenerateReportAsync_WithArtifactsByTestNode_TrxContainsResultFileTrxReportEngine_GenerateReportAsync_WithArtifactsByTestNodeAndCopyFailure_SkipsBadResultFileAndAddsRunInfoThat is expected from the root cause — .NET Framework does not transparently promote Windows paths past
MAX_PATHto 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:
dev/amauryleve/issue-10312-trx-resultfile-net462correctly says ".NET Framework" in its changelog entry rather than naming a version, which is the accurate framing.net472result was initially reported as passing elsewhere: the Arcade test loop aborts afternet462fails, sonet472never 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.