1313using Microsoft . Testing . Platform . Extensions . TestHostControllers ;
1414using Coverlet . MTP . CommandLine ;
1515using Coverlet . Core . Instrumentation ;
16- using Microsoft . Extensions . Configuration ;
1716
1817namespace coverlet . Extension . Collector
1918{
@@ -25,7 +24,7 @@ internal sealed class CoverletExtensionCollector : ITestHostProcessLifetimeHandl
2524 private readonly CoverletLoggerAdapter _logger ;
2625 private readonly CoverletExtensionConfiguration _configuration ;
2726 private IServiceProvider ? _serviceProvider ;
28- private readonly Microsoft . Extensions . Configuration . IConfiguration _platformConfiguration ;
27+ private readonly Microsoft . Testing . Platform . Configurations . IConfiguration ? _platformConfiguration ;
2928 private Coverage ? _coverage ;
3029 private readonly Microsoft . Testing . Platform . Logging . ILoggerFactory _loggerFactory ;
3130 private readonly Microsoft . Testing . Platform . CommandLine . ICommandLineOptions _commandLineOptions ;
@@ -51,15 +50,16 @@ internal sealed class CoverletExtensionCollector : ITestHostProcessLifetimeHandl
5150 public CoverletExtensionCollector (
5251 Microsoft . Testing . Platform . Logging . ILoggerFactory loggerFactory ,
5352 Microsoft . Testing . Platform . CommandLine . ICommandLineOptions commandLineOptions ,
54- Microsoft . Extensions . Configuration . IConfiguration configuration )
53+ Microsoft . Testing . Platform . Configurations . IConfiguration ? configuration )
5554 {
5655 _loggerFactory = loggerFactory ?? throw new ArgumentNullException ( nameof ( loggerFactory ) ) ;
5756 _commandLineOptions = commandLineOptions ?? throw new ArgumentNullException ( nameof ( commandLineOptions ) ) ;
58- _platformConfiguration = configuration ?? throw new ArgumentNullException ( nameof ( configuration ) ) ;
57+ _platformConfiguration = configuration ; // Allow null - coverage flag checked first
5958 _configuration = new CoverletExtensionConfiguration ( ) ;
6059 _logger = new CoverletLoggerAdapter ( _loggerFactory ) ;
6160
62- // Allow attaching debugger via environment variable
61+ // Only run diagnostics if coverage will be enabled
62+ // The actual check happens in BeforeTestHostProcessStartAsync
6363 AttachDebuggerIfRequested ( ) ;
6464
6565 LogDiagnostic ( "CoverletExtensionCollector constructor called" ) ;
@@ -241,6 +241,11 @@ Task ITestHostProcessLifetimeHandler.BeforeTestHostProcessStartAsync(Cancellatio
241241 /// </summary>
242242 private void LogConfigurationDiagnostics ( )
243243 {
244+ if ( _platformConfiguration == null )
245+ {
246+ LogDiagnostic ( "Platform Configuration: null (coverage not enabled)" ) ;
247+ return ;
248+ }
244249 LogDiagnostic ( "Platform Configuration values:" ) ;
245250 try
246251 {
@@ -260,11 +265,20 @@ private void LogConfigurationDiagnostics()
260265 LogDiagnostic ( $ " [{ key } ] = { value ?? "(null)" } ") ;
261266 }
262267
263- // Log all configuration children if accessible
264- IEnumerable < IConfigurationSection > children = _platformConfiguration . GetChildren ( ) ;
265- foreach ( IConfigurationSection child in children )
268+ // Try to enumerate known configuration keys (as a fallback)
269+ string [ ] knownKeys = new [ ]
270+ {
271+ "TestModule" ,
272+ "TestHostController:Mode" ,
273+ "TestHost:Path" ,
274+ "TestAssembly" ,
275+ "TargetPath"
276+ } ;
277+
278+ foreach ( string key in knownKeys )
266279 {
267- LogDiagnostic ( $ " Config child: { child . Key } = { child . Value ?? "(section)" } ") ;
280+ string ? value = _platformConfiguration [ key ] ;
281+ LogDiagnostic ( $ " Config key: { key } = { value ?? "(null)" } ") ;
268282 }
269283 }
270284 catch ( Exception ex )
@@ -353,22 +367,25 @@ private void LogParsedConfigurationDiagnostics()
353367 {
354368 LogDiagnostic ( "Resolving test module path..." ) ;
355369
356- // Try platform configuration first
357- string ? testModule = _platformConfiguration [ "TestModule" ] ;
358- LogDiagnostic ( $ " From config 'TestModule': { testModule ?? "(null)" } ") ;
359- if ( ! string . IsNullOrEmpty ( testModule ) && File . Exists ( testModule ) )
370+ // Only try platform configuration if it exists
371+ if ( _platformConfiguration != null )
360372 {
361- LogDiagnostic ( $ " -> Using TestModule from config") ;
362- return testModule ;
363- }
373+ string ? testModule = _platformConfiguration [ "TestModule" ] ;
374+ LogDiagnostic ( $ " From config 'TestModule': { testModule ?? "(null)" } ") ;
375+ if ( ! string . IsNullOrEmpty ( testModule ) && File . Exists ( testModule ) )
376+ {
377+ LogDiagnostic ( $ " -> Using TestModule from config") ;
378+ return testModule ;
379+ }
364380
365- // Try TestHost:Path
366- testModule = _platformConfiguration [ "TestHost:Path" ] ;
367- LogDiagnostic ( $ " From config 'TestHost:Path': { testModule ?? "(null)" } ") ;
368- if ( ! string . IsNullOrEmpty ( testModule ) && File . Exists ( testModule ) )
369- {
370- LogDiagnostic ( $ " -> Using TestHost:Path from config") ;
371- return testModule ;
381+ // Try TestHost:Path
382+ testModule = _platformConfiguration [ "TestHost:Path" ] ;
383+ LogDiagnostic ( $ " From config 'TestHost:Path': { testModule ?? "(null)" } ") ;
384+ if ( ! string . IsNullOrEmpty ( testModule ) && File . Exists ( testModule ) )
385+ {
386+ LogDiagnostic ( $ " -> Using TestHost:Path from config") ;
387+ return testModule ;
388+ }
372389 }
373390
374391 // Try to get from command line arguments
0 commit comments