question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enabling code coverage leads to errors in child processes

See original GitHub issue

Copy & 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakubch1commented, Feb 13, 2020

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

0reactions
pleonexcommented, May 18, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting code coverage for a child process?
In this blog post, I'm going to explain how to collect code coverage for a process that is launched by another process.
Read more >
Customizing Code Coverage Analysis - Visual Studio
By default, code coverage analyzes all solution assemblies that are loaded during unit tests. We recommend that you use this default behavior, ...
Read more >
Python Code Coverage and Multiprocessing
One of the possible causes of missing coverage data from forked processes, even with concurrency=multiprocessing , is the way of ...
Read more >
Deploying triggers from sandbox to production
Deploying triggers from sandbox to production: Code coverage failure. Trying to deploy development from my sandbox using change sets.
Read more >
Measuring code coverage - Testing Angular
Code coverage, also called test coverage, tells you which parts of your code are executed by running the unit and integration tests. Code ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found