@@ -379,42 +379,48 @@ private async Task TakeDumpAsync()
379379
380380 await _outputDisplay . DisplayAsync ( this , new ErrorMessageOutputDeviceData ( string . Format ( CultureInfo . InvariantCulture , ExtensionResources . CreatingDumpFile , finalDumpFileName ) ) ) ;
381381
382- #if NETCOREAPP
383- DiagnosticsClient diagnosticsClient = new ( _testHostProcessInformation . PID ) ;
384- DumpType dumpType = _dumpType . ToLowerInvariant ( ) . Trim ( ) switch
385- {
386- "mini" => DumpType . Normal ,
387- "heap" => DumpType . WithHeap ,
388- "triage" => DumpType . Triage ,
389- "full" => DumpType . Full ,
390- _ => throw ApplicationStateGuard . Unreachable ( ) ,
391- } ;
392-
393- // Wrap the dump path into "" when it has space in it, this is a workaround for this runtime issue: https://github.com/dotnet/diagnostics/issues/5020
394- // It only affects windows. Otherwise the dump creation fails with: [createdump] The pid argument is no longer supported
395- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && finalDumpFileName . Contains ( ' ' ) )
382+ try
396383 {
397- finalDumpFileName = $ "\" { finalDumpFileName } \" ";
398- }
384+ #if NETCOREAPP
385+ DiagnosticsClient diagnosticsClient = new ( _testHostProcessInformation . PID ) ;
386+ DumpType dumpType = _dumpType . ToLowerInvariant ( ) . Trim ( ) switch
387+ {
388+ "mini" => DumpType . Normal ,
389+ "heap" => DumpType . WithHeap ,
390+ "triage" => DumpType . Triage ,
391+ "full" => DumpType . Full ,
392+ _ => throw ApplicationStateGuard . Unreachable ( ) ,
393+ } ;
394+
395+ // Wrap the dump path into "" when it has space in it, this is a workaround for this runtime issue: https://github.com/dotnet/diagnostics/issues/5020
396+ // It only affects windows. Otherwise the dump creation fails with: [createdump] The pid argument is no longer supported
397+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && finalDumpFileName . Contains ( ' ' ) )
398+ {
399+ finalDumpFileName = $ "\" { finalDumpFileName } \" ";
400+ }
399401
400- diagnosticsClient . WriteDump ( dumpType , finalDumpFileName , true ) ;
402+ diagnosticsClient . WriteDump ( dumpType , finalDumpFileName , true ) ;
401403#else
402- MiniDumpWriteDump . MiniDumpTypeOption miniDumpTypeOption = _dumpType . ToLowerInvariant ( ) . Trim ( ) switch
403- {
404- "mini" => MiniDumpWriteDump . MiniDumpTypeOption . Mini ,
405- "heap" => MiniDumpWriteDump . MiniDumpTypeOption . Heap ,
406- "full" => MiniDumpWriteDump . MiniDumpTypeOption . Full ,
407- _ => throw ApplicationStateGuard . Unreachable ( ) ,
408- } ;
404+ MiniDumpWriteDump . MiniDumpTypeOption miniDumpTypeOption = _dumpType . ToLowerInvariant ( ) . Trim ( ) switch
405+ {
406+ "mini" => MiniDumpWriteDump . MiniDumpTypeOption . Mini ,
407+ "heap" => MiniDumpWriteDump . MiniDumpTypeOption . Heap ,
408+ "full" => MiniDumpWriteDump . MiniDumpTypeOption . Full ,
409+ _ => throw ApplicationStateGuard . Unreachable ( ) ,
410+ } ;
409411
410- MiniDumpWriteDump . CollectDumpUsingMiniDumpWriteDump ( _testHostProcessInformation . PID , finalDumpFileName , miniDumpTypeOption ) ;
412+ MiniDumpWriteDump . CollectDumpUsingMiniDumpWriteDump ( _testHostProcessInformation . PID , finalDumpFileName , miniDumpTypeOption ) ;
411413#endif
412414
413- NotifyCrashDumpServiceIfEnabled ( ) ;
414- using IProcess process = _processHandler . GetProcessById ( _testHostProcessInformation . PID ) ;
415- process . Kill ( ) ;
416- await process . WaitForExitAsync ( ) ;
417- _dumpFileTaken = finalDumpFileName ;
415+ _dumpFileTaken = finalDumpFileName ;
416+ }
417+ finally
418+ {
419+ NotifyCrashDumpServiceIfEnabled ( ) ;
420+ using IProcess process = _processHandler . GetProcessById ( _testHostProcessInformation . PID ) ;
421+ process . Kill ( ) ;
422+ await process . WaitForExitAsync ( ) ;
423+ }
418424 }
419425
420426 private static void NotifyCrashDumpServiceIfEnabled ( )
0 commit comments