Search code examples
c#pkcs#11pkcs11interop

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


I want to develop Application which can read Token and perform PDF Signing. FYI i successfully signed pdf document, but after im update the Pkcs11Interop version from 3.3.0.0 to 4.1.1.0 Then the signed turn into failed. I've tried to enable AutoGenerateBindingRedirects but i still cant sign the PDF

Expecting the PDF is successfully signed, but i get this error

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

what i understand is, this application was trying to call the Pkcs11interop version=3.3.0.0

However its already mention in the Nuget Repo about its dependencies. So it's suppose to be okay right?

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>

what i must do to solve this dependencies error?


Solution

  • I see two problems in what you're trying to do:

    1. Pkcs11Interop 3.3.0 is not strongly signed but all newer versions are. So you would need to redirect from unsigned to signed assembly which AFAIK is not possible.
    2. Pkcs11Interop 4.x contains API changes that are not compatible with 3.x versions so even if you somehow made redirection work Pkcs11Interop.PDF would not be able to use newer version of Pkcs11Interop.

    I might update Pkcs11Interop.PDF for newer versions of Pkcs11Interop but I have no ETA for that yet => currently it's best to just stick to Pkcs11Interop 3.3.0.