Invalid character at position error when setting subject property

0 votes
asked Apr 20, 2011 by Rajat (180 points)
edited Apr 22, 2011

Hi,

The following error was logged in our system. It seems like the error happened when setting the subject property. I'm trying to find out what special characters would cause this error.

Source: Rebex.Mail Message: Invalid character at position 162. Parameter name: value

Stack Trace: at cSVAqj.CkMqVUZ.BIzNVcZ(String , String , Boolean ) at Rebex.Mime.Headers.Unstructured..ctor(String , Boolean ) at Rebex.Mail.MailMessage.set_Subject(String value)

I have tried to set these special characters in the subject and it seems to work:

@, #, $, %, ^, &, *, (, ), +, =, {, }, |, ', ~, `

Your help would be appreciated.

Thank you, Rajat

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Apr 21, 2011 by Lukas Pokorny (88,510 points)
edited Apr 21, 2011

This error is caused by special non-printable characters with ASCII code less than 32 (except the 'tab' character).

For example, the following code will throw the same exception:

C#:

var mail = new MailMessage();
mail.Subject = "Bad character: \x1";

VB.NET:

Dim mail as New MailMessage
mail.Subject = "Bad character: " & Chr(1)
...