.NET / C # certificate read from store throws AccessViolationException

I have a very strange code exception that should work but not work.

I have the following code:

X509Certificate certificate;
X509CertificateStore store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
store.OpenRead();
var certs = new X509CertificateCollection();
Microsoft.Web.Services2.Security.X509.X509CertificateCollection findCertificateBySubjectName = store.FindCertificateBySubjectName("localhost");

foreach (X509Certificate tempCertificate in store.Certificates)
{
    if (String.CompareOrdinal(tempCertificate.Subject, "") == 0)
    {
        certs.Add(tempCertificate);
    }
}

      

enter image description here The current code runs inside the w3wp process under administrator privileges. But I am getting the exception you can see in the screenshot. I tried a lot of things, give access to all certificates, change users, reimport certificate. I would appreciate any help or assistance.

+3


source to share





All Articles