Skip to content

TC build fails to parse .trx file due to file lock #108

@gfraiteur

Description

@gfraiteur

Summary

TeamCity builds frequently fail with a FileNotFoundException / file lock error when parsing .trx test result files. The TC XML report parser tries to read the .trx file while it is still being written by dotnet test, resulting in a The process cannot access the file because it is being used by another process error.

Error

Parsing errors
  Failed to parse 1 report
  artifacts\testResults\ContainerAdministrator_A094B04200D8_2026-03-31_11_03_38.trx:
  C:\wk2\c33f66953b1f6eb\artifacts\testResults\ContainerAdministrator_A094B04200D8_2026-03-31_11_03_38.trx
  (The process cannot access the file because it is being used by another process)
  java.io.FileNotFoundException: ...
    at jetbrains.buildServer.xmlReportPlugin.parsers.mstest.TRXParser.parse(TRXParser.java:152)
    at jetbrains.buildServer.xmlReportPlugin.ParseReportCommand.run(ParseReportCommand.java:62)

Example build

https://postsharp.teamcity.com/buildConfiguration/Metalama_Metalama20261_Metalama_DebugBuild/322251

Analysis

The TC XML Report Processing build feature monitors the artifacts\testResults directory for .trx files. It appears to pick up the file while dotnet test is still writing to it, causing a file lock conflict. This is a race condition between the test runner and TC's report parser.

Possible fixes

  • Add a delay or post-processing step so TC only parses .trx files after dotnet test completes
  • Configure the XML Report Processing build feature to use a different monitoring mode (e.g., parse on finish rather than on-the-fly)
  • Copy .trx files to a separate directory after tests complete and point TC at that directory
  • Use --results-directory with a temp path and copy to artifacts\testResults only after tests finish

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions