Skip to content

[BUG] Collector fails when one of the project's libraries is called collector #1739

Closed
@alex-ntk

Description

@alex-ntk

Tested on two machines, reproducible 100%.

mkdir MySolution
cd MySolution
dotnet new classlib -n MyLibrary
dotnet new console -n Collector
cd Collector
dotnet add reference ../MyLibrary/MyLibrary.csproj
cd ..
dotnet new nunit -n MyTests
cd MyTests
dotnet add reference ../Collector/Collector.csproj
cd ..
dotnet.exe test MyTests\MyTests.csproj --collect:"XPlat Code Coverage"

fails with

Data collector 'XPlat code coverage' message: [coverlet]Coverlet.Collector.Utilities.CoverletDataCollectorExceptio
      n: CoverletCoverageDataCollector: Failed to instrument modules
       ---> System.AggregateException: One or more errors occurred. (The process cannot access the file 'C:\Projects\Cor
      al.TradeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because it is being used by another process
      .) (The process cannot access the file 'C:\Projects\Coral.TradeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Col
      lector.dll' because it is being used by another process.) (The process cannot access the file 'C:\Projects\Coral.T
      radeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because it is being used by another process.) (
      The process cannot access the file 'C:\Projects\Coral.TradeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Collect
      or.dll' because it is being used by another process.) (The process cannot access the file 'C:\Projects\Coral.Trade
      Collector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because it is being used by another process.) (The
      process cannot access the file 'C:\Projects\Coral.TradeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.d
      ll' because it is being used by another process.) (The process cannot access the file 'C:\Projects\Coral.TradeColl
      ector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because it is being used by another process.) (The proc
      ess cannot access the file 'C:\Projects\Coral.TradeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll'
      because it is being used by another process.) (The process cannot access the file 'C:\Projects\Coral.TradeCollecto
      r.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because it is being used by another process.) (The process
      cannot access the file 'C:\Projects\Coral.TradeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' beca
      use it is being used by another process.) (The process cannot access the file 'C:\Projects\Coral.TradeCollector.1\
      MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because it is being used by another process.) (The process cann
      ot access the file 'C:\Projects\Coral.TradeCollector.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because
      it is being used by another process.)
       ---> System.IO.IOException: The process cannot access the file 'C:\Projects\Coral.TradeCollector.1\MySolution\MyT
      ests\bin\Debug\net9.0\Collector.dll' because it is being used by another process.
         at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
         at Coverlet.Core.Helpers.FileSystem.Copy(String sourceFileName, String destFileName, Boolean overwrite) in /_/s
      rc/coverlet.core/Helpers/FileSystem.cs:line 35
         at Coverlet.Core.Helpers.InstrumentationHelper.<>c__DisplayClass17_0.<RestoreOriginalModule>b__0() in /_/src/co
      verlet.core/Helpers/InstrumentationHelper.cs:line 269
         at Coverlet.Core.Helpers.RetryHelper.<>c__DisplayClass0_0.<Retry>b__0() in /_/src/coverlet.core/Helpers/RetryHe
      lper.cs:line 28
         at Coverlet.Core.Helpers.RetryHelper.Do[T](Func`1 action, Func`1 backoffStrategy, Int32 maxAttemptCount) in /_/
      src/coverlet.core/Helpers/RetryHelper.cs:line 55
         --- End of inner exception stack trace ---
         at Coverlet.Core.Helpers.RetryHelper.Do[T](Func`1 action, Func`1 backoffStrategy, Int32 maxAttemptCount) in /_/
      src/coverlet.core/Helpers/RetryHelper.cs:line 62
         at Coverlet.Core.Helpers.RetryHelper.Retry(Action action, Func`1 backoffStrategy, Int32 maxAttemptCount) in /_/
      src/coverlet.core/Helpers/RetryHelper.cs:line 26
         at Coverlet.Core.Helpers.InstrumentationHelper.RestoreOriginalModule(String module, String identifier) in /_/sr
      c/coverlet.core/Helpers/InstrumentationHelper.cs:line 267
         at Coverlet.Core.Coverage.PrepareModules() in /_/src/coverlet.core/Coverage.cs:line 145
         at Coverlet.Collector.DataCollection.CoverageWrapper.PrepareModules(Coverage coverage) in /_/src/coverlet.colle
      ctor/DataCollection/CoverageWrapper.cs:line 71
         at Coverlet.Collector.DataCollection.CoverageManager.InstrumentModules() in /_/src/coverlet.collector/DataColle
      ction/CoverageManager.cs:line 66
       ---> (Inner Exception #1) System.IO.IOException: The process cannot access the file 'C:\Projects\Coral.TradeColle
      ctor.1\MySolution\MyTests\bin\Debug\net9.0\Collector.dll' because it is being used by another process.
         at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
         at Coverlet.Core.Helpers.FileSystem.Copy(String sourceFileName, String destFileName, Boolean overwrite) in /_/s
      rc/coverlet.core/Helpers/FileSystem.cs:line 35
         at Coverlet.Core.Helpers.InstrumentationHelper.<>c__DisplayClass17_0.<RestoreOriginalModule>b__0() in /_/src/co
      verlet.core/Helpers/InstrumentationHelper.cs:line 269
         at Coverlet.Core.Helpers.RetryHelper.<>c__DisplayClass0_0.<Retry>b__0() in /_/src/coverlet.core/Helpers/RetryHe
      lper.cs:line 28
         at Coverlet.Core.Helpers.RetryHelper.Do[T](Func`1 action, Func`1 backoffStrategy, Int32 maxAttemptCount) in /_/
      src/coverlet.core/Helpers/RetryHelper.cs:line 55<---

... another 10 of these

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions