Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The process cannot access the file, because it is being used by another process" error during attempt to collect coverage #1471

Open
tepatelcmc opened this issue May 2, 2023 · 10 comments
Labels
needs more info More details are needed waiting for customer Waiting for customer action

Comments

@tepatelcmc
Copy link

I can see previous issue being fixed in an unofficial version - did it ever make it to stable release?

The issue still exist with running test in parallel with vstest code coverage (XPlat code coverage)

@daveMueller
Copy link
Collaborator

Are you refering to #1155? The fix for this wasn't released yet, but it will be in the next release. You can try out the fix by consuming our nightly build (https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md).

@daveMueller daveMueller added the waiting for customer Waiting for customer action label May 6, 2023
@mathijs-dumon
Copy link

Don't think he means that one, but this one:
#857

I'm facing this issue again when using coverlet.console v6.0.0
Since we didn't have the issue before my guess was a nugget, but it seems like it's actually the dotnet global tool (coverlet.console) which is causing the problem.

Just did some more testing with different versions of the tool: I don't have the issue using v3.1.x or v3.2.0, but I do with v6.0

With v6 I get this kind of exception:

---> System.IO.IOException: The process cannot access the file '(real path left out for nda reasons).pdb' because it is being used by another process.
at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at Coverlet.Core.Helpers.InstrumentationHelper.<>c__DisplayClass17_0.b__0() in //src/coverlet.core/Helpers/InstrumentationHelper.cs:line 295
at Coverlet.Core.Helpers.RetryHelper.<>c__DisplayClass0_0.b__0() in /
/src/coverlet.core/Helpers/RetryHelper.cs:line 29
at Coverlet.Core.Helpers.RetryHelper.Do[T](Func1 action, Func1 backoffStrategy, Int32 maxAttemptCount) in /_/src/coverlet.core/Helpers/RetryHelper.cs:line 55

@mareklinka
Copy link

I just started encountering this same after installing the newly-released C# Dev Kit for VSCode. It seems the processes started by VSCode keep a handle open on the assemblies:

TpTrace Warning: 0 : 20944, 1, 2023/06/07, 15:33:20.113, 4930720815067, datacollector.dll, [coverlet]Unable to instrument module: C:\Source\Personal\fourth-pharos\backend\FourthPharos.Domain.Tests\bin\Debug\net7.0\FourthPharos.Domain.dll
System.IO.IOException: The process cannot access the file 'C:\Source\Personal\fourth-pharos\backend\FourthPharos.Domain.Tests\bin\Debug\net7.0\FourthPharos.Domain.dll' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at Coverlet.Core.Helpers.FileSystem.NewFileStream(String path, FileMode mode, FileAccess access) in /_/src/coverlet.core/Helpers/FileSystem.cs:line 52
   at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in /_/src/coverlet.core/Instrumentation/Instrumenter.cs:line 207
   at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in /_/src/coverlet.core/Instrumentation/Instrumenter.cs:line 149
   at Coverlet.Core.Coverage.PrepareModules() in /_/src/coverlet.core/Coverage.cs:line 135

Once I close VSCode and run dotnet test again, instrumentation works as expected. Probably not much Coverlet can do about it, just wanted to mention it. I'll open an issue in the Dev Kit repo, once it goes public.

@github-actions
Copy link

This issue is stale because it has been open for 3 months with no activity.

@github-actions github-actions bot added the stale label Sep 10, 2023
@roryprimrose
Copy link

This has been a problem for my team as we have minimum code coverage being applied to changed code as a policy in pull requests. This bug is preventing us from being able to complete pull requests.

I have found that with this bug in 6.0.0, we get this error in the dotnet test build log and 0% coverage reported for that project. I tried downgrading to 3.2.0. That version didn't throw the error but also reported 0% coverage. I have downgraded to 3.1.2 which:

  • does not throw the error
  • correctly reports coverage percentage
  • correctly identifies and excludes coverage for assemblies that are not in the repository

@github-actions github-actions bot removed the stale label Oct 15, 2023
Copy link

This issue is stale because it has been open for 3 months with no activity.

@github-actions github-actions bot added the stale label Jan 14, 2024
@Bertk Bertk added the needs more info More details are needed label Feb 7, 2024
@Bertk
Copy link
Collaborator

Bertk commented Feb 7, 2024

Issue should be closed because the related coverlet nuget package is not mentioned and comments for all packages are available. The new issue template for bugs should improve this.

@github-actions github-actions bot removed the stale label Feb 11, 2024
Copy link

This issue is stale because it has been open for 3 months with no activity.

@github-actions github-actions bot added the stale label May 12, 2024
@tripleacoder
Copy link

tripleacoder commented May 14, 2024

I get the same error on one of my .NET 4.8 projects.

I am using the coverlet console tool as part of an Azure Pipeline.

Tool version is 6.0.2

The exit code from coverlet is 255, which is undocumented.

Command:

coverlet C:\agents\A1\_work\64/RAT.IntTest.dll --target dotnet --targetargs test C:\agents\A1\_work\64/RAT.IntTest.dll --no-build --logger trx --diag:log.txt --format cobertura --source-mapping-file C:\agents\A1\_work\64/SourceMapping.txt --use-source-link --output C:\agents\A1\_work\64/coverage/coverage.cobertura.xml --verbosity detailed

Output:

(...)
BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
TryWithCustomResolverOnDotNetCore for PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Unable to instrument module: C:\agents\A1_work\64\RAT.exe
Coverlet.Core.Exceptions.CecilAssemblyResolutionException: AssemblyResolutionException for 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Try to add true to test projects or pass '/p:CopyLocalLockFileAssemblies=true' option to the 'dotnet test' command-line
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
--- End of inner exception stack trace ---
at Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver.TryWithCustomResolverOnDotNetCore(AssemblyNameReference name) in //src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs:line 217
at Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver.Resolve(AssemblyNameReference name) in /
/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs:line 129
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
at Mono.Cecil.MetadataBuilder.AddParameter(UInt16 sequence, ParameterDefinition parameter, ParamTable table)
at Mono.Cecil.MetadataBuilder.AddParameters(MethodDefinition method)
at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddTypes()
at Mono.Cecil.MetadataBuilder.BuildTypes()
at Mono.Cecil.MetadataBuilder.BuildModule()
at Mono.Cecil.MetadataBuilder.BuildMetadata()
at Mono.Cecil.ModuleWriter.<>c.b__2_0(MetadataBuilder builder, MetadataReader )
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func3 read) at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata) at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in /
/src/coverlet.core/Instrumentation/Instrumenter.cs:line 325
at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 148
at Coverlet.Core.Coverage.PrepareModules() in /
/src/coverlet.core/Coverage.cs:line 135
One or more errors occurred. (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.)
Unhandled exception. System.AggregateException: One or more errors occurred. (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.)
---> System.IO.IOException: The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.

BadImageFormatException during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.
TryWithCustomResolverOnDotNetCore for PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Unable to instrument module: C:\agents\A1_work\64\RAT.exe
Coverlet.Core.Exceptions.CecilAssemblyResolutionException: AssemblyResolutionException for 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Try to add true to test projects or pass '/p:CopyLocalLockFileAssemblies=true' option to the 'dotnet test' command-line
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
--- End of inner exception stack trace ---
at Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver.TryWithCustomResolverOnDotNetCore(AssemblyNameReference name) in //src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs:line 217
at Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver.Resolve(AssemblyNameReference name) in /
/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs:line 129
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
at Mono.Cecil.MetadataBuilder.AddParameter(UInt16 sequence, ParameterDefinition parameter, ParamTable table)
at Mono.Cecil.MetadataBuilder.AddParameters(MethodDefinition method)
at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddTypes()
at Mono.Cecil.MetadataBuilder.BuildTypes()
at Mono.Cecil.MetadataBuilder.BuildModule()
at Mono.Cecil.MetadataBuilder.BuildMetadata()
at Mono.Cecil.ModuleWriter.<>c.b__2_0(MetadataBuilder builder, MetadataReader )
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func3 read) at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata) at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in /
/src/coverlet.core/Instrumentation/Instrumenter.cs:line 325
at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in //src/coverlet.core/Instrumentation/Instrumenter.cs:line 148
at Coverlet.Core.Coverage.PrepareModules() in /
/src/coverlet.core/Coverage.cs:line 135
One or more errors occurred. (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.)
Unhandled exception. System.AggregateException: One or more errors occurred. (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.) (The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.)
---> System.IO.IOException: The process cannot access the file 'C:\agents\A1_work\64\RAT.pdb' because it is being used by another process.

@github-actions github-actions bot removed the stale label May 19, 2024
@roryprimrose
Copy link

We still have this issue on 6.0.0, 6.0.1 and 6.0.2. Version 3.2.0 still works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More details are needed waiting for customer Waiting for customer action
Projects
None yet
Development

No branches or pull requests

7 participants