Sitelet https://github.com/coverlet-coverage/coverlet/pull/1988
Skip to content

Replicate in-proc collector improvements from PR #1987 to MTP handler - #1988

Merged
Bertk merged 1 commit into
coverlet-coverage:masterfrom
bkoelman:fix-assembly-scanning-mtp
Jul 22, 2026
Merged

Bertk merged 1 commit into
coverlet-coverage:masterfrom
bkoelman:fix-assembly-scanning-mtp

Conversation

@bkoelman

Copy link
Copy Markdown
Contributor

This PR applies the reliability improvements made to the legacy in-proc collector (PR #1987) to the new Microsoft Testing Platform (MTP) in-process handler:

  1. Replace assembly scanning with AppDomain registry: GetAssemblies() + GetTypes() scanning silently drops any assembly that throws ReflectionTypeLoadException. By using the ConcurrentBag<EventHandler> registry populated during module load, we avoid reflection entirely and prevent silent coverage loss.
  2. Always log flush failures: Exceptions thrown by UnloadModule are now logged unconditionally as errors. The COVERLET_MTP_INPROC_EXCEPTIONLOG_ENABLED environment variable now controls whether these exceptions are rethrown to abort the test run, rather than whether they are logged at all.
  3. Fix environment variable propagation: Corrected a bug in CoverletExtensionEnvironmentVariableProvider where it was mistakenly passing the out-of-proc variable (COVERLET_MTP_EXCEPTIONLOG_ENABLED) to the test host instead of the correct in-proc variable (COVERLET_MTP_INPROC_EXCEPTIONLOG_ENABLED).

This applies the reliability improvements made to the legacy in-proc collector (PR #1987) to the new Microsoft Testing Platform (MTP) in-process handler:
1. Replace assembly scanning with `AppDomain` registry: `GetAssemblies()` + `GetTypes()` scanning silently drops any assembly that throws `ReflectionTypeLoadException`. By using the `ConcurrentBag<EventHandler>` registry populated during module load, we avoid reflection entirely and prevent silent coverage loss.
2. Always log flush failures: Exceptions thrown by `UnloadModule` are now logged unconditionally as errors. The `COVERLET_MTP_INPROC_EXCEPTIONLOG_ENABLED` environment variable now controls whether these exceptions are rethrown to abort the test run, rather than whether they are logged at all.
3. Fix environment variable propagation: Corrected a bug in `CoverletExtensionEnvironmentVariableProvider` where it was mistakenly passing the out-of-proc variable (`COVERLET_MTP_EXCEPTIONLOG_ENABLED`) to the test host instead of the correct in-proc variable (`COVERLET_MTP_INPROC_EXCEPTIONLOG_ENABLED`).

Signed-off-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
@bkoelman

Copy link
Copy Markdown
Contributor Author

I have run all tests on Windows and in WSL/Ubuntu, but have not tried with the coverlet-examples.

@bkoelman
bkoelman marked this pull request as ready for review July 20, 2026 23:14
@bkoelman
bkoelman force-pushed the fix-assembly-scanning-mtp branch from 43576d0 to 43680e9 Compare July 20, 2026 23:14
@Bertk Bertk added enhancement General enhancement request driver-MTP Issue related to Microsoft Testing Platform driver labels Jul 21, 2026
@Bertk
Bertk merged commit 856637d into coverlet-coverage:master Jul 22, 2026
10 checks passed
This was referenced Sep 27, 2026
This was referenced Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

driver-MTP Issue related to Microsoft Testing Platform driver enhancement General enhancement request

Projects

None yet

2 participants