Friday, October 15, 2010

Client Certificate: FormatException Invalid Hexadecimal string format

Ran into this exception while trying to add a client certificate to a SOAP client.
After installing the certificate through the mmc->Certificate snap-in I tried to copy the Thumbprint of the said certificate so that my client application would be able to use it.
The snap-in dispays the thumbprint as follows:
34 f7 83 fc 40 f6 1d d7 1c 92 43 c9 a5 af aa 42 ba 5e 27 db
So I just copied it and inserted it into my app.config.
First exception was from the fact that the thumbprint needs to be a string without spaces, converted the string to:
This time I got the exception FormatException: Invalid Hexadecimal string format. I copied the string from the snap-in again and this time I pasted it into Notepad++ to see if there were anything else hidden in the string. As it turned out there was.
?34 f7 83 fc 40 f6 1d d7 1c 92 43 c9 a5 af aa 42 ba 5e 27 db
So pasting back into the app.config and this time removing the starting character and the starting quote and manually writing them back and the just to be safe doing the same thing with the ending character and the ending quote it worked. Don’t forget to remove the spaces as well.
Hope this helps somebody out there as it really slowed me down last night. : )


  1. thank you, I had the same problem and I had not found the cause.

  2. Thx, this one saved me some time.
    Note to anyone that is having the same issue, you might have to change the encoding around a bit in Notepad++ to get the strange characters to appear

  3. Thanks too, I have the same problem.

  4. Thanks, this article and sdec's comment did help me. I would like to share one more tip. If you tried to paste the thumbprint, then deleted it, and then typed manually, then you might have left some characters still (although you cannot see it). The solution is to delete that line altogether and then paste it as suggested by removing that (ugly :-) )character.

  5. Yepp. Visual Studio should highlight or mark invisible characters! 'View white space' doesn't cut it.

  6. thanks a lot, same problem with serial certificate and findby function on visual studio. Thanks again

    1. Hi there, I'm glad that this old article still helps! :)