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
Summary
TeamCity builds frequently fail with a
FileNotFoundException/ file lock error when parsing.trxtest result files. The TC XML report parser tries to read the.trxfile while it is still being written bydotnet test, resulting in aThe process cannot access the file because it is being used by another processerror.Error
Example build
https://postsharp.teamcity.com/buildConfiguration/Metalama_Metalama20261_Metalama_DebugBuild/322251
Analysis
The TC XML Report Processing build feature monitors the
artifacts\testResultsdirectory for.trxfiles. It appears to pick up the file whiledotnet testis 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
.trxfiles afterdotnet testcompletes.trxfiles to a separate directory after tests complete and point TC at that directory--results-directorywith a temp path and copy toartifacts\testResultsonly after tests finish