Enabling code coverage leads to errors in child processes
See original GitHub issueCopy & pasting the info from #1263 as requested since the issue is still present and the workaround doesn’t work.
Description
I have a test project that targets .NET Framework 4.7.2 and .NET Core 3.1. The test starts a child process that targets also .NET Framework and .NET Core (same version and each version of the test runs the matching framework).
However, the child process that targets .NET Core crashes with the following exception:
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
The reason seems to be because the Code Coverage is injected into child process also.
As reported in #1263 after it was closed, we can not override the profiling environment variables. For instance, I tried with but the issue still happens:
process.StartInfo.EnvironmentVariables["CORECLR_ENABLE_PROFILING"] = "0";
process.StartInfo.EnvironmentVariables["COR_ENABLE_PROFILING"] = "0";
Steps to reproduce
@dasMulli already provided a good reproducer: repro-subproc-profiling.zip
Just run it with dotnet test --collect "Code Coverage"
Expected behavior
No crash, it works, there is a way to disable profiling in children process.
Actual behavior
It crash and workaround doesn’t work.
Diagnostic logs
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Environment
Running with dotnet test --collect "Code Coverage"
on Windows 10 with VS 2019 16.4.2 Enterprise and .NET Core 3.1.100
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Could you please confirm that you have this package installed: https://www.nuget.org/packages/Microsoft.CodeCoverage/16.5.0 ?
It can be easily installed by:
dotnet add package Microsoft.CodeCoverage --version 16.5.0
Sorry for the late reply, for some reason I forgot about this. Today I worked again with the project I was having the issue and now I can confirm that by adding that package (well now to version 16.6.1) in the child process that my tests run (no need to add in the test project as
Microsoft.NET.Test.Sdk
does it for you), the issue is fixed 🎉Thanks!