"The process cannot access the file, because it is being used by another process" error during attempt to collect coverage
See original GitHub issueThe error message for MSBuild intergration
C:\Users\xxx\.nuget\packages\coverlet.msbuild\2.8.1\build\coverlet.msbuild.targets(36,5): error : One or more errors occurred. (The process cannot access the file 'D:\Work\xxx\yyy\test\yyy.Tests\bin\Debug\netcoreapp2.1\zzz.Dto.dll' because it is being used by another process.)[D:\Work\xxx\yyy\test\yyy.Tests\yyy.Tests.csproj]
C:\Users\xxx\.nuget\packages\coverlet.msbuild\2.8.1\build\coverlet.msbuild.targets(36,5): error : at Coverlet.Core.Helpers.RetryHelper.Do[T](Func`1 action, Func`1 backoffStrategy, Int32 maxAttemptCount) in c:\git\coverletToRelease\src\coverlet.core\Helpers\RetryHelper.cs:line 59 [D:\Work\xxx\yyy\test\yyy.Tests\yyy.Tests.csproj]
C:\Users\xxx\.nuget\packages\coverlet.msbuild\2.8.1\build\coverlet.msbuild.targets(36,5): error : at Coverlet.Core.Helpers.RetryHelper.Retry(Action action, Func`1 backoffStrategy, Int32 maxAttemptCount) in c:\git\coverletToRelease\src\coverlet.core\Helpers\RetryHelper.cs:line 28 [D:\Work\xxx\yyy\test\yyy.Tests\yyy.Tests.csproj]
C:\Users\xxx\.nuget\packages\coverlet.msbuild\2.8.1\build\coverlet.msbuild.targets(36,5): error : at Coverlet.Core.Helpers.InstrumentationHelper.RestoreOriginalModule(String module, String identifier) in c:\git\coverletToRelease\src\coverlet.core\Helpers\InstrumentationHelper.cs:line 219 [D:\Work\xxx\yyy\test\yyy.Tests\yyy.Tests.csproj]
C:\Users\xxx\.nuget\packages\coverlet.msbuild\2.8.1\build\coverlet.msbuild.targets(36,5): error : at Coverlet.Core.Coverage.GetCoverageResult() in c:\git\coverletToRelease\src\coverlet.core\Coverage.cs:line 219 [D:\Work\xxx\yyy\test\yyy.Tests\yyy.Tests.csproj]
C:\Users\xxx\.nuget\packages\coverlet.msbuild\2.8.1\build\coverlet.msbuild.targets(36,5): error : at Coverlet.MSbuild.Tasks.CoverageResultTask.Execute() in c:\git\coverletToRelease\src\coverlet.msbuild.tasks\CoverageResultTask.cs:line 113 [D:\Work\xxx\yyy\test\yyy.Tests\yyy.Tests.csproj]
The same behavior for VSTest integration
---> (Inner Exception #1) System.IO.IOException: The process cannot access the file 'D:\Work\xxx\yyy\test\yyy.Tests\bin\Debug\netcoreapp2.1\zzz.dll' because it is being used by another process.
at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at Coverlet.Core.Helpers.FileSystem.Copy(String sourceFileName, String destFileName, Boolean overwrite) in c:\git\coverletToRelease\src\coverlet.core\Helpers\FileSystem.cs:line 33
at Coverlet.Core.Helpers.InstrumentationHelper.<>c__DisplayClass10_0.<RestoreOriginalModule>b__0() in c:\git\coverletToRelease\src\coverlet.core\Helpers\InstrumentationHelper.cs:line 215
at Coverlet.Core.Helpers.RetryHelper.<>c__DisplayClass0_0.<Retry>b__0() in c:\git\coverletToRelease\src\coverlet.core\Helpers\RetryHelper.cs:line 26
at Coverlet.Core.Helpers.RetryHelper.Do[T](Func`1 action, Func`1 backoffStrategy, Int32 maxAttemptCount) in c:\git\coverletToRelease\src\coverlet.core\Helpers\RetryHelper.cs:line 52<---
It happens all the time, when I try to collect coverage for xunit test projects (with NUnit everything works fine suddenly) using default commands, like dotnet test --collect:"XPlat Code Coverage"
or dotnet test /p:CollectCoverage=true
Adding -nr:false -m:1
arguments to MSBuild didn’t help, as well as running commands with separate csproj
file. I’ve used the latest versions of coverlet
, xunit
and Microsoft.NET.Test.Sdk
packages
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Moq" Version="4.14.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Installed SDKs are below
.NET Core SDK (reflecting any global.json):
Version: 3.1.202
Commit: 6ea70c8dca
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.202\
Host (useful for support):
Version: 3.1.4
Commit: 0c2e69caa6
.NET Core SDKs installed:
2.1.806 [C:\Program Files\dotnet\sdk]
3.1.202 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Migrated from comments of 725 issue
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:27
Top Results From Across the Web
Fixed: The Process Cannot Access The File Used by ...
According to user reports, the “the process cannot access the file because it is being used by another process write to disk” error...
Read more >Azure devops release pipeline runs forever with error
Azure devops release pipeline runs forever with error: The process cannot access the file because it is being used by another process ·...
Read more >The process cannot access the file because it is being ...
Hello. I'm trying to save files in DB, which should record the file as "BinaryData". I'm using RadAsyncUpload, but when i upload the...
Read more >FIX The Process Cannot Access the File Because It ... - YouTube
This post will help you resolve the error where the process cannot access the file because it is being used by another process....
Read more >Process can't access the file because it is being used by ...
This error usually means that either the user or someone else still has that file open. This can happen if the file referenced...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Uploaded
coverlet.msbuild.2.9.1-preview.6.g1f7fe02d13
same feeds.BTW my advice is to use collectors because has got better integration and doesn’t suffer of some issues https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/KnownIssues.md#1-vstest-stops-process-execution-earlydotnet-test
Please let me know if works as expected!
@AntiPasha I’m working on a workaround/solution, can you try with this package(collectors driver
dotnet test --collect:"XPlat Code Coverage"
)nuget feed source https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json package version
1.3.1-preview.6.g1f7fe02d13
This is the feed I use for preview/investigation.
Branch https://github.com/coverlet-coverage/coverlet/compare/master...MarcoRossignoli:issue857