I am using StringBuilder AppendLine to insert some lines to be shown in a javascript alert box. The alert box is not firing and wehn I see the view source I get the following:
alert("Void SendMail(Int32):
Line number: 0
Object reference not set to an instance of an object.
");
StringBuilder code:
sb.AppendLine(string.Format("{0}: ", frame.GetMethod()));
sb.AppendLine(string.Format("Line number: {0} ", frame.GetFileLineNumber()));
sb.AppendLine(ex.Message);
Please tell me how to fix this ?
Instead of
StringBuilder.ToString()you should probably useStringBuilder.ToString().Replace(Environment.NewLine, "\\n"). This should escape the newlines in the javascript, so the result is:I genuinely hope you’re logging the exception somewhere serverside too.