首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XpsDocument.SignDigitally在IsSignable上抛出NullReferenceException

XpsDocument.SignDigitally在IsSignable上抛出NullReferenceException
EN

Stack Overflow用户
提问于 2021-01-08 18:26:13
回答 1查看 28关注 0票数 0

我遇到了标题中提到的方法的问题。如果我试图签署一个XPS文档,它会运行到NullReferenceException:

at System.Windows.Xps.Packaging.XpsDocument.get_IsSignable() at System.Windows.Xps.Packaging.XpsDocument.SignDigitally(X509Certificate证书,布尔embedCertificate,XpsDigSigPartAlteringRestrictions限制,字符串signatureId,Boolean testIsSignable) at System.Windows.Xps.Packaging.XpsDocument.SignDigitally(X509Certificate证书,Boolean embedCertificate,XpsDigSigPartAlteringRestrictions限制)

任何建议都将不胜感激。

代码语言:javascript
复制
    if (sign_digitally)
    {
        UserCertificateSelector selector = new UserCertificateSelector();
        if (selector.ShowDialog() == true)
            {
                var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
#if DEBUG
                X509CertificateCollection collection = certStore.Certificates;
#else
                X509CertificateCollection collection = certStore.Certificates.Find(X509FindType.FindByThumbprint, selector.SelectedCertificate.CertificateThumbPrint,true);
#endif
                if (collection.Count > 0)
                {
                    xpsDoc.SignDigitally(collection[0], true, XpsDigSigPartAlteringRestrictions.None);
                 }
             }
         }
...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-10 21:21:31

确保您处理的是XPS文件格式,而不是OXPS。两者都可以作为XpsDocument打开,但只有XPS可以签名。你可以检查"XpsDocument.IsSignable“标志,一旦你打开文件-对于OXPS,它将是空的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65627275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档