0

I have a problem using the X509Store.Certificates.Find function when running my wcf service as LocalSystem.

The StoreLocation is 'LocalMachine' and the StoreName is 'My'.

When running my service as an administrator this function has no problems of finding the requested certificate.

Code i use:

X509Certificate2Collection collection = store.Certificates.Find(findType, findValue, true);

As mentioned before: running the windows service as administrator works fine, as LocalSystem it does not.

I'm not getting any errors, the new collection is just empty, but in both cases store.Certificates contains the requested certificate.

When i use the following code it works fine.

foreach (X509Certificate2 certificate in store.Certificates)
{
    if (certificate.Subject == findValue)
        //do stuff
}

Can someone explain me why the Certificates.Find function is not working properly?

Tymmoty
  • 1
  • 1
  • Do you get an exception, or an event in Windows Event Log? I think you'll just have to grant the user permissions to read the private keys. Like said [here](http://stackoverflow.com/questions/5097572/x-509-certificate-cannot-be-found-by-wcf-service?rq=1), [here](http://stackoverflow.com/questions/216109/cannot-find-the-x-509-certificate-using-the-following-search-criteria?rq=1), [here](http://stackoverflow.com/questions/2987066/cannot-find-the-x-509-certificate-after-publishing?rq=1) and in plenty of the other related questions that were suggested when you were typing this question. – CodeCaster Jun 13 '13 at 12:27
  • No exception or logs. The new collection is empty. My question is why is this possible when the certificates are all in store.Certificates. – Tymmoty Jun 13 '13 at 12:30
  • You specify `true` for the `validOnly` parameter of `Find()`, is it valid? – CodeCaster Jun 13 '13 at 12:32
  • It is valid, but also tried with false. – Tymmoty Jun 13 '13 at 12:33
  • Welcome to StackOverflow ! in order to get useful help try adding as much relevant inflammation like which error do you get and what was your code referance – Mzf Jun 13 '13 at 12:36
  • Thank you. I edited the question with the part i don't get any errors and that store.Collections contains the requested certificate in both situations. – Tymmoty Jun 13 '13 at 13:03
  • what is your variable `findType` equal to? – wal Jun 13 '13 at 14:40
  • Tried multiple: FindByThumbprint, FindBySubjectName, FindBySubjectDistinguishedName.. – Tymmoty Jun 13 '13 at 14:43

0 Answers0