10
I have a given certificate installed on my server. That certificate has valid dates, and seems perfectly valid in the Windows certificates MMC snap-in.
However, when I try to read the certificate, in order to use it in an HttpRequest, I can't find it. Here is the code used:
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly); X509Certificate2Collection col =
store.Certificates.Find(X509FindType.FindBySerialNumber, "xxx", true);
xxx is the serial number; the argument true means "only valid certificates". The returned collection is empty.
The strange thing is that if I pass false, indicating invalid certificates are acceptable, the collection contains one element—the certificate with the specified serial number.
In conclusion: the certificate appears valid, but the Find method treats it as invalid! Why?