Esempio n. 1
0
        public static IList <StackFrameInfo> GetFrames(Exception exception)
        {
            var frames = new List <StackFrameInfo>();

            if (exception == null)
            {
                return(frames);
            }

            using (var portablePdbReader = new PortablePdbReader())
            {
                var needFileInfo = true;
                var stackTrace   = new System.Diagnostics.StackTrace(exception, needFileInfo);
                var stackFrames  = stackTrace.GetFrames();

                if (stackFrames == null)
                {
                    return(frames);
                }

                for (var i = 0; i < stackFrames.Length; i++)
                {
                    var frame  = stackFrames[i];
                    var method = frame.GetMethod();

                    // Always show last stackFrame
                    if (!ShowInStackTrace(method) && i < stackFrames.Length - 1)
                    {
                        continue;
                    }

                    var stackFrame = new StackFrameInfo
                    {
                        StackFrame        = frame,
                        FilePath          = frame.GetFileName(),
                        LineNumber        = frame.GetFileLineNumber(),
                        MethodDisplayInfo = GetMethodDisplayString(frame.GetMethod()),
                    };

                    if (string.IsNullOrEmpty(stackFrame.FilePath))
                    {
                        // .NET Framework and older versions of mono don't support portable PDBs
                        // so we read it manually to get file name and line information
                        portablePdbReader.PopulateStackFrame(stackFrame, method, frame.GetILOffset());
                    }

                    frames.Add(stackFrame);
                }

                return(frames);
            }
        }
Esempio n. 2
0
        public static IList <StackFrameInfo> GetFrames(Exception exception)
        {
            var frames = new List <StackFrameInfo>();

            if (exception == null)
            {
                return(frames);
            }

#if NET451
            using (var portablePdbReader = new PortablePdbReader())
#endif
            {
                var needFileInfo = true;
                var stackTrace   = new System.Diagnostics.StackTrace(exception, needFileInfo);
                var stackFrames  = stackTrace.GetFrames();

                if (stackFrames == null)
                {
                    return(frames);
                }

                foreach (var frame in stackFrames)
                {
                    var method = frame.GetMethod();

                    var stackFrame = new StackFrameInfo
                    {
                        StackFrame = frame,
                        FilePath   = frame.GetFileName(),
                        LineNumber = frame.GetFileLineNumber(),
                        Method     = method.Name,
                    };

#if NET451
                    if (string.IsNullOrEmpty(stackFrame.FilePath))
                    {
                        // .NET Framework and older versions of mono don't support portable PDBs
                        // so we read it manually to get file name and line information
                        portablePdbReader.PopulateStackFrame(stackFrame, method, frame.GetILOffset());
                    }
#endif

                    frames.Add(stackFrame);
                }

                return(frames);
            }
        }