来自商店的.NET / C#读取证书导致AccessViolationException

时间:2015-06-08 08:08:04

标签: c# .net certificate x509certificate access-violation

我得到了非常奇怪的代码异常,这应该可行但不起作用。

我有以下代码:

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 当前代码在管理员权限下的w3wp进程内运行。但是我在截图中看到了异常。我尝试了很多东西,让所有证书都可以访问,更改用户,重新导入证书。 如有任何帮助或帮助,我将不胜感激。

0 个答案:

没有答案