private Element StackTrace(Exception exception, string expression) { Element stackTrace = new Element("span").AddStyleClass("stackTrace"); stackTrace.SetId("stackTrace" + buttonId); Element p = new Element("p") .AppendText("While evaluating expression: "); p.AppendChild(new Element("code").AppendText(expression)); stackTrace.AppendChild(p); var stackTraceElements = new List<string> { String.Format("{0}: {1}", exception.GetType().ToString(), exception.Message) }; stackTraceElements.AddRange(exception.StackTrace.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)); foreach (var stackTraceElement in stackTraceElements) { stackTrace.AppendChild(StackTraceElement(stackTraceElement)); } //RecursivelyAppendStackTrace(exception, stackTrace); return stackTrace; }