0

I have some code that sends emails when there is an error. One of the things it includes is the "Stack Trace". Well sometimes that Stack Trace ends up with some "special characters" or escape sequences that get converted to special characters, it looks something like this:

at CrystalDecisions.CrystalReports.Engine.FormatEngine.W(Stream q, String r)

You can see the special characters at the end, "(Stream q, String r)." In this example its acutally a 0x08. I have another example where its 0x03 and 0x1a. This causes and "Invalid Char" exception. I'm wondering if there is a way to scan/replace any/all "invalid chars" before sending the message? I dont' want to have to "know" all the possible invalid chars. The call being made is:

ExchangeServices.SendEmail(creds, fromEmailAddr, toEmailAddr, subject, body)

I have verified that its in the StackTrace output in visual studio. Its not caused by converting the string in my code.

dbl

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
dblwizard
  • 595
  • 7
  • 26
  • 1
    What are the "special characters" in that string? They're all printable. – Etienne de Martel Jun 23 '23 at 15:15
  • Those boxes are neither special characters nor escape sequences. They're the result of trying to send/convert text with non-US-ASCII characters using the wrong codepage. Either the wrong encoding was used in the message (eg ASCII instead of UTF8) or some code that wasn't posted here tried to "fix" codepages and mangled the text – Panagiotis Kanavos Jun 23 '23 at 15:16
  • What are you using to send the message? By default SmtpClient.SendMail uses US-ASCII. You need to use the overload that specifies UTF8 as the body's encoding – Panagiotis Kanavos Jun 23 '23 at 15:19
  • Sorry the characters showed when I was previewing the message but they don't show now. Using UxD editor there is a 0x08 character in the string in front of the q and r. I will review the code before the error handler but things are just passed as String. – dblwizard Jun 23 '23 at 15:58
  • 0x08? That's a backspace. Where is that stack trace coming from? – Etienne de Martel Jun 23 '23 at 19:13
  • These are coming out of a .net45 application with some older libraries. I'm just trying to catch this when it errors. I am looking at ways to remove any control character but have to try and not remove any Chr(13) Char(10) as that will change the format of the message. – dblwizard Jun 23 '23 at 19:22

0 Answers0