Using an instance built by default parameterless constructor will cause exception or miscalculation. To avoid this, always use parameter-based constructors. This will not be fixed due to consideration about running speed.
Microsoft digs lots of pits, and I keep jumping among them.
Recently, I wrote a program using HttpClient in dotNet to post some data to server through HTTP Post. The server is set with client certificate required.
My designing is simple:
Open X509Store to query the certificate by using thumbprint.
Attach the certificate found in step 1 into WebRequestHandler.
Pass the handler created in step 2 to the instance of HttpClient and send the request.
Required by step 1, I need to type the thumbprint of the certificate into code. The steps I did:
Open certificate from Windows. It’s shown up like this:
Copy the text of Thumbprint and paste it into a notepad.
Replace all spaces to nothing.
Copy the new text into code.
When I run the code, it ended in a strange way. No certificate is found by using the thumbprint I provided. I dig a long time before I found this pit prepared by Microsoft: The text, copied from the window above (in step 1), contains hidden lead bytes “0x200E”. These bytes won’t display in code view of Visual Studio, nor in Notepad.