From ae4e6d813c3a6d0dd6d8602842df0d7df20ea471 Mon Sep 17 00:00:00 2001 From: Satya Madala Date: Tue, 10 Apr 2018 20:10:07 +0530 Subject: [PATCH] Fix to show right error message on assembly load exception during test run. (#395) * Fix to show right error message on assembly load exception during test run * Add logging --- .../Execution/StackTraceHelper.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs b/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs index f8ace86fe9..e08f35a6cd 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs @@ -67,9 +67,29 @@ internal static StackTraceInformation GetStackTraceInformation(Exception ex) // Sometimes the stacktrace can be null, but the inner stacktrace // contains information. We are not interested in null stacktraces // so we simply ignore this case - if (curException.StackTrace != null) + try + { + if (curException.StackTrace != null) + { + stackTraces.Push(curException.StackTrace); + } + } + catch (Exception e) { - stackTraces.Push(curException.StackTrace); + // curException.StackTrace can throw exception, Although MSDN doc doesn't say that. + try + { + // try to get stacktrace + if (e.StackTrace != null) + { + stackTraces.Push(e.StackTrace); + } + } + catch (Exception) + { + PlatformServiceProvider.Instance.AdapterTraceLogger.LogError( + "StackTraceHelper.GetStackTraceInformation: Failed to get stacktrace info."); + } } }