System.IO.FileLoadException: 无法加载文件或程序集 'Pkcs11Interop,版本 = 3.3.0.0

System.IO.FileLoadException: Could not load file or assembly 'Pkcs11Interop, Version=3.3.0.0

我想开发可以读取令牌并执行 PDF 签名的应用程序。仅供参考,我成功签署了 pdf 文档,但是在我将 Pkcs11Interop 版本从 3.3.0.0 更新到 4.1.1.0 之后,签名变成了失败。我已尝试启用 AutoGenerateBindingRedirects 但我仍然无法签署 PDF

期待 PDF 成功签名,但我收到此错误

System.IO.FileLoadException: Could not load file or assembly 'Pkcs11Interop, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Screenshot error

据我了解,此应用程序试图调用 Pkcs11interop version=3.3.0.0

但是它已经在 Nuget Repo 中提到了它的依赖项。所以应该没问题吧?

Pkcs11Interop.PDF

/* App.config */

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
    <dependentAssembly>
        <assemblyIdentity name="Pkcs11Interop" publicKeyToken="c10e9c2d8c006d2a"/>
        <bindingRedirect oldVersion="3.3.0.0" newVersion="4.1.1.0"/>
    </dependentAssembly>
</configuration>

我必须做什么来解决这个依赖错误?

我发现您的操作存在两个问题:

  1. Pkcs11Interop 3.3.0 没有强签名,但所有较新的版本都是。因此,您需要从未签名的程序集重定向到已签名的程序集,据我所知这是不可能的。
  2. Pkcs11Interop 4.x 包含 API 与 3.x 版本不兼容的更改,因此即使您以某种方式进行了重定向,Pkcs11Interop.PDF 也无法使用较新的版本Pkcs11Interop 的。

我可能会更新 Pkcs11Interop.PDF 以获得较新版本的 Pkcs11Interop,但我还没有 ETA => 目前最好坚持使用 Pkcs11Interop 3.3.0。