I have a problem when I use store.Certificates.Find. I am using Windows server 2008 R2 with NET 3.5. The cert is installed by
public static void AddCertificate(X509Certificate2 cert, StoreName name = StoreName.My, StoreLocation location = StoreLocation.LocalMachine)
{
var store = new X509Store(name, location);
store.Open(OpenFlags.ReadWrite);
store.Add(cert);
store.Close();
}
After that, find the certificate by
string certThumbprint = "XXXX";
var certificates = store.Certificates.Find(X509FindType.FindByThumbprint, commandLineArgs.CertificateThumbprint, true);
if (certificates.Count == 0)
{
throw new ArgumentException("No certificate found with given thumbprint.");
}
The exception should not be thrown at all, yet it seems to be thrown sometimes. It throws exceptions about 5 times per 100 runs.
I have googled and found the "invisible first character" issue, but in my case, the thumbprint is indeed hardcoded. I am not reading the thumbprint from anywhere. The exactly codes run on windows server 2012 with NET.4.5 have never given me any problems. This only applies to windows server with NET.3.5. I am wondering why the results are so inconsistent only on WS2008R2?
I think that the problem might be that your user dont have permisions for the certificate
Try this